Coverage for pySDC/projects/Monodomain/run_scripts/run_MonodomainODE_cli.py: 100%
35 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
1import argparse
2from pySDC.projects.Monodomain.run_scripts.run_MonodomainODE import setup_and_run
5def list_of_ints(arg):
6 arg = arg.replace(' ', '')
7 arg = arg.replace('_', '-')
8 arg = arg.split(',')
9 return list(map(int, arg))
12# This is to run the MonodomainODE example from the command line
13# Pretty much all the parameters can be defined from the command line
15# For the refinements, it is possible to set negative values, which yield a mesh coarser than the baseline.
16# To do so in the command line use an underscore _ insteaf of a minus sign -.
17# For example, to solve a 3 level example with meshes refinements 1, 0 and -1, use the option --refinements 1,0,_1
20def main():
21 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
22 # define sweeper parameters
23 parser.add_argument("--integrator", default="IMEXEXP_EXPRK", type=str, help="sweeper name")
24 parser.add_argument(
25 "--num_nodes",
26 default="4",
27 type=list_of_ints,
28 help="list of ints (as '5,3', i.e. no brackets): number of collocation nodes per level",
29 )
30 parser.add_argument("--num_sweeps", default="1", type=list_of_ints, help="list of ints: number of sweeps per level")
31 parser.add_argument(
32 "--skip_res",
33 default=False,
34 action=argparse.BooleanOptionalAction,
35 help="compute residual only when really needed",
36 )
37 # set step parameters
38 parser.add_argument("--max_iter", default=100, type=int, help="maximal number of iterations")
39 # set level parameters
40 parser.add_argument("--dt", default=0.05, type=float, help="step size")
41 parser.add_argument("--restol", default=5e-8, type=float, help="residual tolerance")
42 # problem args
43 parser.add_argument(
44 "--domain_name", default="cuboid_2D_small", type=str, help="cuboid_2D, cuboid_3D, truncated_ellipsoid,..."
45 )
46 parser.add_argument(
47 "--refinements",
48 default="0",
49 type=list_of_ints,
50 help="list of ints: number of refinements per level, with respect to a baseline mesh (negative values yield coarser meshes). For negative values use _ instead of -.",
51 )
52 parser.add_argument(
53 "--order", default="4", type=list_of_ints, help="list of ints: order of FEM or FD discretization"
54 )
55 parser.add_argument("--ionic_model_name", default="TTP", type=str, help="ionic_model: HH, CRN, TTP")
56 parser.add_argument(
57 "--read_init_val", default=False, action=argparse.BooleanOptionalAction, help="read the initial value from file"
58 )
59 parser.add_argument("--init_time", default=0.0, type=float, help="duration of stimulus. -1 means default")
60 parser.add_argument(
61 "--enable_output",
62 default=False,
63 action=argparse.BooleanOptionalAction,
64 help="activate or deactivate xdmf output: True or False",
65 )
66 parser.add_argument(
67 "--write_as_reference_solution",
68 default=False,
69 action=argparse.BooleanOptionalAction,
70 help="write as reference solution: True or False",
71 )
72 parser.add_argument(
73 "--write_all_variables",
74 default=False,
75 action=argparse.BooleanOptionalAction,
76 help="when write_as_reference_solution=True, write write all variables (True) or only potential V (False)",
77 )
78 parser.add_argument("--end_time", default=1.0, type=float, help="end time. If negative, a default one is used")
79 parser.add_argument("--output_file_name", default="monodomain", type=str, help="output file name")
80 parser.add_argument("--ref_sol", default="ref_sol", type=str, help="reference solution file name")
81 parser.add_argument("--output_root", default="results_tmp/", type=str, help="output root folder")
82 parser.add_argument(
83 "--finter",
84 default=False,
85 action=argparse.BooleanOptionalAction,
86 help="in prolong, re-evaluate f (false) or interpolate (true)",
87 )
88 # controller args
89 parser.add_argument(
90 "--truly_time_parallel",
91 default=False,
92 action=argparse.BooleanOptionalAction,
93 help="truly time parallel or emulated",
94 )
95 parser.add_argument("--n_time_ranks", default=1, type=int, help="number of time ranks")
97 parser.add_argument(
98 "--write_database",
99 default=True,
100 action=argparse.BooleanOptionalAction,
101 help="save some simulation results in a database",
102 )
104 args = parser.parse_args()
106 error_L2, rel_error_L2, avg_niters, times, niters, residuals = setup_and_run(
107 args.integrator,
108 args.num_nodes,
109 args.skip_res,
110 args.num_sweeps,
111 args.max_iter,
112 args.dt,
113 args.restol,
114 args.domain_name,
115 args.refinements,
116 args.order,
117 args.ionic_model_name,
118 args.read_init_val,
119 args.init_time,
120 args.enable_output,
121 args.write_as_reference_solution,
122 args.write_all_variables,
123 args.output_root,
124 args.output_file_name,
125 args.ref_sol,
126 args.end_time,
127 args.truly_time_parallel,
128 args.n_time_ranks,
129 args.finter,
130 args.write_database,
131 )
134if __name__ == "__main__":
135 main()