diff --git a/Tests/Data/Parabolic/ComponentTransport/MultiLayerDiffusion/MultiLayerDiffusion.ipynb b/Tests/Data/Parabolic/ComponentTransport/MultiLayerDiffusion/MultiLayerDiffusion.ipynb index 958fa35f8d668787541cfaa9286f74653d4fbfc0..d1cfcbec8cbb7517cf4ee763cebdc0f9f5a061df 100644 --- a/Tests/Data/Parabolic/ComponentTransport/MultiLayerDiffusion/MultiLayerDiffusion.ipynb +++ b/Tests/Data/Parabolic/ComponentTransport/MultiLayerDiffusion/MultiLayerDiffusion.ipynb @@ -265,7 +265,7 @@ " color_map = iter(cm.rainbow(np.linspace(0, 1, len(time))))\n", "\n", " # Plot semi-analytical solutions\n", - " for col_name, t, color in zip(soln[[\"1e3\", \"1e4\", \"1e5\", \"1e6\"]], time, color_map):\n", + " for col_name, _t, color in zip(soln[[\"1e3\", \"1e4\", \"1e5\", \"1e6\"]], time, color_map):\n", " ax.plot(\n", " soln[\"x\"],\n", " soln[col_name],\n", @@ -352,7 +352,7 @@ } ], "source": [ - "from IPython.display import Image, display\n", + "from IPython.display import display\n", "\n", "display(Image(filename=\"./sketch_molar_flux_calculation.jpg\", width=400))" ] diff --git a/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/CO2Injection/CO2Injection.md b/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/CO2Injection/CO2Injection.md index 511c263dced93a64a15d26b06e05d30f49e25d77..b32bf2f1fdbc79cd4916e4c84694b7d5c1a9e88b 100644 --- a/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/CO2Injection/CO2Injection.md +++ b/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/CO2Injection/CO2Injection.md @@ -88,7 +88,8 @@ check_file = os.path.isfile(f"{out_dir}/calcite_simple_ts_43_t_30000.000000.vtu" if check_file: print("OGS simulation for the scenario simple case runs successfully") else: - raise Exception("OGS simulation failed.") + msg = "OGS simulation failed." + raise Exception(msg) # pwp prj_name = "calcite_pwp.prj" @@ -106,7 +107,8 @@ check_file = os.path.isfile(f"{out_dir}/calcite_pwp_ts_43_t_30000.000000.vtu") if check_file: print("OGS simulation for the scenario PWP case runs successfully") else: - raise Exception("OGS simulation failed.") + msg = "OGS simulation failed." + raise Exception(msg) ``` ```python diff --git a/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/DecayChain.ipynb b/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/DecayChain.ipynb index a13cf21781f6060f0a313dd7abadcbf67f774530..750e5fe934edbc8d2ee451280d9eff50c11d4455 100644 --- a/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/DecayChain.ipynb +++ b/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/DecayChain.ipynb @@ -191,7 +191,7 @@ "source": [ "def computeProduct(j, i, k, c_inlet):\n", " value = 1\n", - " for l in range(j, i):\n", + " for l in range(j, i): # noqa: E741\n", " value *= k[l] / (k[l] - k[i]) * c_inlet[j]\n", "\n", " return value\n", diff --git a/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/GlobalImplicitApproach/performance_measurements.ipynb b/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/GlobalImplicitApproach/performance_measurements.ipynb index e7280929cf45b8e6450f2ee84f206ed20e942f4d..f122f03a36d0f4720b016180c0058c4ff2279cac 100644 --- a/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/GlobalImplicitApproach/performance_measurements.ipynb +++ b/Tests/Data/Parabolic/ComponentTransport/ReactiveTransport/DecayChain/GlobalImplicitApproach/performance_measurements.ipynb @@ -78,7 +78,12 @@ } ], "source": [ - "out_dir_base = os.environ.get(\"OGS_TESTRUNNER_OUT_DIR\", \"_out\")\n", + "from pathlib import Path\n", + "\n", + "out_dir_base = Path(os.environ.get(\"OGS_TESTRUNNER_OUT_DIR\", \"_out\"))\n", + "if not out_dir_base.exists():\n", + " out_dir_base.mkdir(parents=True)\n", + "\n", "print(\"base output directory is\", out_dir_base)" ] }, @@ -90,7 +95,7 @@ "outputs": [], "source": [ "def get_out_dir(case):\n", - " return os.path.join(out_dir_base, os.path.dirname(case))" + " return out_dir_base / Path(case).parent" ] }, { @@ -179,15 +184,15 @@ } ], "source": [ - "for name, case in cases:\n", + "for _name, case in cases:\n", " outdir = get_out_dir(case)\n", - " if not os.path.exists(outdir):\n", - " os.makedirs(outdir)\n", - " with open(os.path.join(outdir, \".gitignore\"), \"w\") as fh:\n", + " if not outdir.exists():\n", + " outdir.mkdir(parents=True)\n", + " with (outdir / \".gitignore\").open(mode=\"w\") as fh:\n", " fh.write(\"*\\n\")\n", "\n", " print(f\"running case {case}\")\n", - " with open(os.path.join(outdir, \"ogs-out.txt\"), \"w\") as fh:\n", + " with (outdir / \"ogs-out.txt\").open(mode=\"w\") as fh:\n", " subprocess.run(\n", " [\"ogs\", \"-o\", outdir, case], check=True, stdout=fh, stderr=subprocess.STDOUT\n", " )" @@ -349,9 +354,9 @@ "stats = []\n", "exec_times = []\n", "\n", - "for name, case in cases:\n", + "for _name, case in cases:\n", " outdir = get_out_dir(case)\n", - " logfile = os.path.join(outdir, \"ogs-out.txt\")\n", + " logfile = outdir / \"ogs-out.txt\"\n", "\n", " records = parse_file(logfile)\n", "\n", @@ -385,7 +390,7 @@ "# df_stats = stats[0].copy()\n", "# df_stats[\"case_name\"] = cases[0][0]\n", "\n", - "for (name, case), stat in zip(cases, stats):\n", + "for (name, _case), stat in zip(cases, stats):\n", " tmp = stat.copy()\n", " tmp[\"case_name\"] = name\n", " df_stats = pd.concat([df_stats, tmp])\n", @@ -523,7 +528,7 @@ "source": [ "assert np.all(df_it_num[\"min\"] == df_it_num[\"max\"])\n", "# attention: depends on the order of cases!\n", - "assert np.all(df_it_num[\"max\"].values == [2, 1, 1, 2, 1, 1, 2, 1, 1])" + "assert np.all(df_it_num[\"max\"].values == [2, 1, 1, 2, 1, 1, 2, 1, 1]) # noqa: PD011" ] }, { @@ -779,7 +784,7 @@ "df_time_step_speedups[\"dirichlet_time\"] /= df_time_step_speedups[\"iteration_number\"]\n", "\n", "for col in df_time_step_speedups.columns:\n", - " c = df_time_step_speedups[col].values\n", + " c = df_time_step_speedups[col].to_numpy()\n", " # c[:3] = np.max(c[:3]) / c[:3]\n", " # c[3:] = np.max(c[3:]) / c[3:]\n", " c[:3] = c[0] / c[:3]\n", @@ -854,7 +859,7 @@ "assert np.all(df_time_step_speedups.index == [name for name, case in cases])\n", "\n", "for col in df_time_step_speedups.columns:\n", - " c = df_time_step_speedups[col].values\n", + " c = df_time_step_speedups[col].to_numpy()\n", " # c[:3] = np.max(c[:3]) / c[:3]\n", " # c[3:] = np.max(c[3:]) / c[3:]\n", " c[:3] = c[0] / c[:3]\n", @@ -928,9 +933,9 @@ "computes = []\n", "solves = []\n", "\n", - "for name, case in cases:\n", + "for _name, case in cases:\n", " outdir = get_out_dir(case)\n", - " logfile = os.path.join(outdir, \"ogs-out.txt\")\n", + " logfile = outdir / \"ogs-out.txt\"\n", "\n", " res = subprocess.run(\n", " f'grep \"compute with Eigen .* linear solver\" {logfile} | wc -l',\n", @@ -1129,7 +1134,7 @@ "simulation_results = {}\n", "\n", "for name, case in cases:\n", - " pvdfile = os.path.join(get_out_dir(case), \"1d_decay_chain_GIA.pvd\")\n", + " pvdfile = get_out_dir(case) / \"1d_decay_chain_GIA.pvd\"\n", " print(\"reading\", pvdfile)\n", " reader = pv.get_reader(pvdfile)\n", " # print(reader.time_values)\n", diff --git a/Tests/Data/Parabolic/ComponentTransport/elder/elder-python-bcs.py b/Tests/Data/Parabolic/ComponentTransport/elder/elder-python-bcs.py index 487aa5419938d1e4ee3317e8cf92ea4f767a752a..9946f3130a773282b772423d885f8836bb97f48a 100644 --- a/Tests/Data/Parabolic/ComponentTransport/elder/elder-python-bcs.py +++ b/Tests/Data/Parabolic/ComponentTransport/elder/elder-python-bcs.py @@ -5,7 +5,7 @@ except ModuleNotFoundError: class BCPressure(OpenGeoSys.BoundaryCondition): - def getDirichletBCValue(self, t, coords, node_id, primary_vars): + def getDirichletBCValue(self, _t, coords, _node_id, _primary_vars): x, y, z = coords if x == -150 and z == 75: @@ -17,7 +17,7 @@ class BCPressure(OpenGeoSys.BoundaryCondition): class BCConcentration(OpenGeoSys.BoundaryCondition): - def getDirichletBCValue(self, t, coords, node_id, primary_vars): + def getDirichletBCValue(self, _t, coords, _node_id, _primary_vars): x, y, z = coords if z == -75: diff --git a/Tests/Data/Parabolic/LiquidFlow/BlockingConductingFracture/BlockingConductingFracture.ipynb b/Tests/Data/Parabolic/LiquidFlow/BlockingConductingFracture/BlockingConductingFracture.ipynb index d5446562b9b3778a0875da6d764500268dde3ade..cfac425871e4d917d2454bd372635116dc762304 100644 --- a/Tests/Data/Parabolic/LiquidFlow/BlockingConductingFracture/BlockingConductingFracture.ipynb +++ b/Tests/Data/Parabolic/LiquidFlow/BlockingConductingFracture/BlockingConductingFracture.ipynb @@ -117,9 +117,7 @@ ], "source": [ "# Run the analysis\n", - "model_lf.run_model(\n", - " logfile=os.path.join(out_dir, \"block_conduct_frac.txt\"), args=f\"-o {out_dir}\"\n", - ")" + "model_lf.run_model(logfile=(out_dir / \"block_conduct_frac.txt\"), args=f\"-o {out_dir}\")" ] }, { @@ -232,9 +230,6 @@ ], "source": [ "# Post-Processing\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "\n", "levels = np.linspace(np.min(field), np.max(field), 60)\n", "levelsf = np.linspace(np.min(field), np.max(field), 60)\n", "\n",