1+ import re
12from itertools import chain
23from typing import TypedDict
3- import re
44
5- from .bout_v5_input_file_upgrader import add_parser_general , run_general
65from boutdata .data import BoutOptionsFile
76
7+ from .bout_v5_input_file_upgrader import add_parser_general , run_general
8+
9+
810class Replacement (TypedDict ):
911 old : str
1012 new : str
1113
14+
1215REPLACEMENTS = []
1316DELETED = []
1417
1518NEW_NAMES = {
16- "collisions" : ["braginskii_collisions" , "braginskii_friction" , "braginskii_heat_exchange" ],
19+ "collisions" : [
20+ "braginskii_collisions" ,
21+ "braginskii_friction" ,
22+ "braginskii_heat_exchange" ,
23+ ],
1724 "electron_viscosity" : ["braginskii_electron_viscosity" ],
1825 "ion_viscosity" : ["braginskii_ion_viscosity" ],
19- "thermal_force" : ["braginskii_thermal_force" ]
26+ "thermal_force" : ["braginskii_thermal_force" ],
2027}
2128
2229COMPONENT_RE = re .compile (r"[+\-\w]+" )
@@ -30,7 +37,11 @@ def update_component_names(options_file: BoutOptionsFile) -> None:
3037 for section_name in components :
3138 section = options_file .getSection (section_name )
3239 explicit_types = "type" in section
33- types = [tname .strip () for tname in section ["type" ].split ("," )] if explicit_types else [section_name ]
40+ types = (
41+ [tname .strip () for tname in section ["type" ].split ("," )]
42+ if explicit_types
43+ else [section_name ]
44+ )
3445 open_paren = types [0 ][0 ] == "("
3546 close_paren = types [- 1 ][- 1 ] == ")"
3647 if open_paren :
@@ -42,7 +53,11 @@ def update_component_names(options_file: BoutOptionsFile) -> None:
4253 if "recycling" in new_types :
4354 recycling_component = section_name
4455 if new_types != types :
45- section ["type" ] = ("(" if open_paren else "" ) + ", " .join (new_types ) + (")" if close_paren else "" )
56+ section ["type" ] = (
57+ ("(" if open_paren else "" )
58+ + ", " .join (new_types )
59+ + (")" if close_paren else "" )
60+ )
4661 # Add braginskii_conduction to the end of the list of components
4762 if has_collisions :
4863 components .append ("braginskii_conduction" )
@@ -52,8 +67,12 @@ def update_component_names(options_file: BoutOptionsFile) -> None:
5267 components .append (recycling_component )
5368 options_file ["hermes:components" ] = "(" + ", " .join (components ) + ")"
5469
70+
5571def run (args ) -> None :
56- run_general (REPLACEMENTS , DELETED , args , additional_modifications = update_component_names )
57-
72+ run_general (
73+ REPLACEMENTS , DELETED , args , additional_modifications = update_component_names
74+ )
75+
76+
5877def add_parser (subcommand , default_args , files_args ):
5978 return add_parser_general (subcommand , default_args , files_args , run , "Hermes-3" )
0 commit comments