From 429c099e47f396725fbf98cc0dde3db8ab797131 Mon Sep 17 00:00:00 2001
From: Tobias Meisel <tobias.meisel@ufz.de>
Date: Tue, 19 Mar 2024 17:38:19 +0100
Subject: [PATCH] [logparser] split docu for logparser

---
 ...y.py => plot_efficiency_study_advanced.py} | 13 ++--
 .../plot_efficiency_study_analysis.py         | 69 +++++++++++++++++++
 .../plot_efficiency_study_intro.py            | 42 +++++++++++
 3 files changed, 117 insertions(+), 7 deletions(-)
 rename docs/examples/howto_studies/{plot_efficiency_study.py => plot_efficiency_study_advanced.py} (85%)
 create mode 100644 docs/examples/howto_studies/plot_efficiency_study_analysis.py
 create mode 100644 docs/examples/howto_studies/plot_efficiency_study_intro.py

diff --git a/docs/examples/howto_studies/plot_efficiency_study.py b/docs/examples/howto_studies/plot_efficiency_study_advanced.py
similarity index 85%
rename from docs/examples/howto_studies/plot_efficiency_study.py
rename to docs/examples/howto_studies/plot_efficiency_study_advanced.py
index 92d6b9f9a..ac306dd88 100644
--- a/docs/examples/howto_studies/plot_efficiency_study.py
+++ b/docs/examples/howto_studies/plot_efficiency_study_advanced.py
@@ -1,12 +1,12 @@
 """
-Efficiency study
-=================
+Efficiency study - Advanced topics
+==================================
 
 This example shows how to analyse the  OGS log output to get information
 about performance of different parts of ogs.
-It uses the project file from the following benchmark:
-`ogs: LiquidFlow (Primary variable constraint Dirichlet-type boundary condition)
-<https://www.opengeosys.org/docs/benchmarks/liquid-flow/primary-variable-constrain-dirichlet-boundary-condition/>`_
+It uses a log file generated by ogs with project file from the following benchmark:
+
+
 """
 
 # %%
@@ -56,7 +56,7 @@ analysis_convergence_newton_iteration(df_log)
 
 # %%
 # Staggered
-
+# Tests/Data/Parabolic/HT/StaggeredCoupling/HeatTransportInStationaryFlow/HeatTransportInStationaryFlow.prj#
 records = parse_file(
     "/home/meisel/gitlabrepos/ogstools/staggered_heat_transport_in_stationary_flow.log"
 )
@@ -80,5 +80,4 @@ x.plot(subplots=True, sharex=True, grid=True)
 
 # Computing logs takes to much time
 # custom regexes, log level
-
 # force_parallel
diff --git a/docs/examples/howto_studies/plot_efficiency_study_analysis.py b/docs/examples/howto_studies/plot_efficiency_study_analysis.py
new file mode 100644
index 000000000..6be42b180
--- /dev/null
+++ b/docs/examples/howto_studies/plot_efficiency_study_analysis.py
@@ -0,0 +1,69 @@
+"""
+Efficiency study - Predefined Analyses
+=======================================
+
+Here we shows the different predefined analysis available in the log parser.
+We uses the project file from the following benchmark:
+`ogs: Constant viscosity (Hydro-Thermal)
+<https://www.opengeosys.org/docs/benchmarks/hydro-thermal/constant-viscosity/>` with
+`<t_end> 1e8 </t_end>`
+and for the staggered scheme the variant taken from
+`Tests/Data/Parabolic/HT/StaggeredCoupling/HeatTransportInStationaryFlow/HeatTransportInStationaryFlow.prj`
+"""
+
+# %%
+import pandas as pd
+
+from ogstools.studies.efficiency import (
+    analysis_convergence_coupling_iteration,
+    analysis_convergence_newton_iteration,
+    analysis_time_step,
+    fill_ogs_context,
+    parse_file,
+    time_step_vs_iterations,
+)
+from ogstools.studies.efficiency.examples import (
+    const_viscosity_thermal_convection_log,
+)
+
+# %%
+log = const_viscosity_thermal_convection_log
+records = parse_file(log)
+df_records = pd.DataFrame(records)
+df_log = fill_ogs_context(df_records)
+
+# %%
+# Every time step of the simulation and how many iterations have been needed.
+df_ts_it = time_step_vs_iterations(df_log)
+df_ts_it  # noqa: B018
+
+
+# %%
+# Performance of in separate parts by time step
+df_ts = analysis_time_step(df_log)
+df_ts = df_ts.loc[0]
+# log of serial so we can remove MPI_process (index=0) from result (all are 0) - see advanced
+df_ts  # noqa: B018
+# %%
+# Performance of in separate parts by time step - plot
+df_ts[
+    ["output_time", "assembly_time", "dirichlet_time", "linear_solver_time"]
+].plot(logy=True, grid=True)
+
+# %%
+# Analysis of convergence criteria - Newton iterations
+analysis_convergence_newton_iteration(df_log)
+
+
+# %%
+# Staggered
+# Tests/Data/Parabolic/HT/StaggeredCoupling/HeatTransportInStationaryFlow/HeatTransportInStationaryFlow.prj#
+#
+records = parse_file(
+    "/home/meisel/gitlabrepos/ogstools/staggered_heat_transport_in_stationary_flow.log"
+)
+df_records = pd.DataFrame(records)
+df_log = fill_ogs_context(df_records)
+
+# Only for staggered coupled processes
+analysis_convergence_coupling_iteration(df_log)
diff --git a/docs/examples/howto_studies/plot_efficiency_study_intro.py b/docs/examples/howto_studies/plot_efficiency_study_intro.py
new file mode 100644
index 000000000..5755a48e6
--- /dev/null
+++ b/docs/examples/howto_studies/plot_efficiency_study_intro.py
@@ -0,0 +1,42 @@
+"""
+Efficiency study - Introduction
+================================
+
+This basic example shows a how to analyse the OGS log output to get information
+about performance of different parts of ogs.
+It uses the project file from the following benchmark:
+`ogs: Constant viscosity (Hydro-Thermal)
+<https://www.opengeosys.org/docs/benchmarks/hydro-thermal/constant-viscosity/>` with
+`<t_end> 1e8 </t_end>`
+"""
+
+# %%
+import pandas as pd
+
+from ogstools.studies.efficiency import (
+    fill_ogs_context,
+    parse_file,
+    time_step_vs_iterations,
+)
+from ogstools.studies.efficiency.examples import (
+    const_viscosity_thermal_convection_log,
+)
+
+# %%
+log = const_viscosity_thermal_convection_log
+# Purpose of records and fill_ogs_context is explained in advanced section
+records = parse_file(log)
+df_records = pd.DataFrame(records)
+df_log = fill_ogs_context(df_records)
+# This is one of many predined analyses. All possibilities are show here:
+# Here we are interested in every time step of the simulation and how many iterations have been needed.
+# For analysis runs only with log of log-level `ogs -l info` or `ogs - l debug` according to
+# `OpenGeoSys Docs: Log and Debug Output <https://www.opengeosys.org/docs/devguide/advanced/log-and-debug-output/>`
+
+df_ts_it = time_step_vs_iterations(df_log)
+# The result is a pandas.DataFrame. You may manipulate the dataframe to your needs with pandas functionality.
+df_ts_it  # noqa: B018
+
+# %%
+# Or directly use pandas functionality to plot.
+df_ts_it.plot(grid=True)
-- 
GitLab