@@ -33,6 +33,7 @@ def precice_env_setup(environment):
3333 if yaml_target .exists ():
3434 yaml_target .unlink ()
3535
36+
3637def run (inp_file , precice_cfg , participant = "Solid" , ccx_cmd = "ccx_preCICE" ,
3738 mesh_name = "Solid-Nodes-Mesh" , interface_name = "Solid-Interface" ,
3839 read_data = "DisplacementDelta" , write_data = "Force" ):
@@ -53,21 +54,49 @@ def run(inp_file, precice_cfg, participant="Solid", ccx_cmd="ccx_preCICE",
5354 with precice_env_setup (environment ):
5455 run_cmd = [
5556 ccx_cmd ,
56- "-i" , inp_stem_name ,
57+ "-i" ,
58+ inp_stem_name ,
5759 "-precice-participant" , participant
5860 ]
5961 subprocess .run (run_cmd , check = True , cwd = work_dir )
6062
6163 return work_dir / f"{ inp_stem_name } .frd"
6264
6365
64- def cleanup (sim_folder , remove_spooles = True ):
65- """Method to clean up all calculix files except paraview output ."""
66+ def cleanup (sim_folder , exclude = None ):
67+ """Method to clean up all calculix files except specifically excluded ."""
6668 sim_folder = Path (sim_folder )
67- spooles_file = Path (__file__ ).resolve ().parent / "spooles.out"
6869
69- if remove_spooles and spooles_file .exists ():
70- spooles_file .unlink ()
70+ patterns = [
71+ "precice*" ,
72+ "exchange*" ,
73+ "m2n*" ,
74+ "*.nam" ,
75+ "*.sur" ,
76+ "*.log" ,
77+ "*.lock" ,
78+ "spooles.out" ,
79+ "*.cvg" ,
80+ "*.dat" ,
81+ "*.inp" ,
82+ "*.sta" ,
83+ "*.12d"
84+ ]
85+
86+ if not exclude :
87+ exclude = []
88+
89+ if isinstance (exclude , str ):
90+ exclude = [exclude ]
91+
92+ if not isinstance (exclude , list ):
93+ raise TypeError ("exclude must be a string or list" )
7194
72- if sim_folder .exists () and sim_folder .is_dir ():
73- shutil .rmtree (sim_folder )
95+ for pattern in patterns :
96+ for p in sim_folder .glob (pattern ):
97+ if p .name in exclude :
98+ continue
99+ if p .is_dir ():
100+ shutil .rmtree (p , ignore_errors = True )
101+ else :
102+ p .unlink ()
0 commit comments