TNO Intern

Release/optimize r out

Merge request reports

Loading
+5
Changes for docs/manual/simulation_configuration.md: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -229,6 +229,7 @@ Supported parameters include:
- Tgrad  
- Q  
- fluid_percent  
- r_out  

Supported sampling distributions and their corresponding arguments for the configuration JSON are:

@@ -256,6 +257,10 @@ optimization simulation, see the example for [Optimization of a coaxial BHE](../
> and upwards in the inner pipe. Optimization of the pipe radius for
> this design is only supported for the inner pipe.

> When `r_out` is optimized, its resulting value can differ between samples.
> In that case, `r_out` is stored per-sample (dimensions `samples`; `nPipes`)
> in the results file instead of the usual single locked-parameter value.

---

## Simulation results 
+2 −2
Changes for src/geoloop/bin/SingleRunSim.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ def optimize_forkeys(
        x0[i] = 0.5 * sum(boundsval[i])

    method = "Nelder-Mead"
    method = "Powell"
    # method = "Powell"

    # ftol is tolerance for output power error of optimized point
    result = minimize(
@@ -70,7 +70,7 @@ def optimize_forkeys(
        args=(optimize_keys, config, copcrit, isample),
        bounds=boundsval,
        method=method,
        options={"maxiter": 50, "ftol": 100},
        options={"maxiter": 50, "fatol": 5},
    )

    return result, config
+10 −2
Changes for src/geoloop/geoloopcore/CoaxialPipe.py: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -198,8 +198,11 @@ class CoaxialPipe(CustomPipe):
        R_f_out_out = 1.0 / (h_f_a_out * 2 * np.pi * r_out_in)
        R_fp = R_p_out + R_f_out_out

        r_inner = np.roll(self.r_in, 1)
        r_outer = np.roll(self.r_out, 1)
        # r_inner = np.roll(self.r_in, 1)
        # r_outer = np.roll(self.r_out, 1)

        r_inner = self.r_in
        r_outer = self.r_out

        self.coaxial = gt.pipes.Coaxial(
            (0, 0), r_inner, r_outer, self.b, k_s, k_g[0], R_ff, R_fp, J=self.J
@@ -498,6 +501,11 @@ class CoaxialPipe(CustomPipe):
        if abs(np.sum(qbz) - power) > 1:
            print("power is not sumq (sumq, power):", np.sum(qbz), ",", power)

        # Reff = -np.average(Tf - Tb) * bh.H / (power + 1e-6)

        if abs(power) > 1e-3:
            Reff = -np.average(Tf - Tb) * bh.H / power
        else:
            Reff = -1

        return T_f_out, power, Reff, ptemp, Tb, qbz
+21 −7
Changes for src/geoloop/plotting/create_plots.py: 21 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -84,16 +84,23 @@ class PlotResults:
        ]
        variable_param_names, locked_param_names = get_param_names()

        x_variables = result_variables + variable_param_names
        x_variables = result_variables + variable_param_names + ["r_out"]

        # Loop through variables and create scatterplots
        for x_variable in x_variables:
            if x_variable != y_variable and x_variable in results_df.columns:
                # only plot the variables that are truly variable (stdev != 0)
                if results_df[x_variable].std().round(7) != 0:
                    title = f"{format_dict[x_variable]} ({units_dict[x_variable]}) after {results_df.loc[0, 'hours']} hours production vs. {format_dict[y_variable]} ({units_dict[y_variable]})"
                    # Handle r_out unit conversion
                    plot_df = results_df.copy()
                    x_unit = units_dict[x_variable]
                    if x_variable == "r_out":
                        plot_df[x_variable] = plot_df[x_variable] * 1000
                        x_unit = "mm"

                    title = f"{format_dict[x_variable]} ({x_unit}) after {plot_df.loc[0, 'hours']} hours production vs. {format_dict[y_variable]} ({units_dict[y_variable]})"
                    g = sns.JointGrid(
                        results_df, x=x_variable, y=y_data[y_variable], hue="file_name"
                        plot_df, x=x_variable, y=y_data[y_variable], hue="file_name"
                    )
                    g.plot_joint(
                        sns.scatterplot, alpha=0.7, edgecolor=".2", linewidth=0.5
@@ -118,7 +125,7 @@ class PlotResults:
                        )
                        g.ax_joint.legend()  # Ensure the legend is updated
                    g.set_axis_labels(
                        xlabel=f"{format_dict[x_variable]} ({units_dict[x_variable]})",
                        xlabel=f"{format_dict[x_variable]} ({x_unit})",
                        ylabel=f"{format_dict[y_variable]} ({units_dict[y_variable]})",
                    )
                    g.fig.suptitle(title)
@@ -135,9 +142,16 @@ class PlotResults:
                in params_df.select_dtypes(include=["float64", "int64"]).columns
            ):
                if params_df[x_variable].std().round(7) != 0:
                    title = f"{format_dict[x_variable]} ({units_dict[x_variable]}) after {params_df.loc[0, 'nyear']} year production vs. {format_dict[y_variable]} ({units_dict[y_variable]})"
                    # Handle r_out unit conversion
                    plot_params_df = params_df.copy()
                    x_unit = units_dict[x_variable]
                    if x_variable == "r_out":
                        plot_params_df[x_variable] = plot_params_df[x_variable] * 1000
                        x_unit = "mm"

                    title = f"{format_dict[x_variable]} ({x_unit}) after {plot_params_df.loc[0, 'nyear']} year production vs. {format_dict[y_variable]} ({units_dict[y_variable]})"
                    g = sns.JointGrid(
                        params_df, x=x_variable, y=y_data[y_variable], hue="file_name"
                        plot_params_df, x=x_variable, y=y_data[y_variable], hue="file_name"
                    )
                    g.plot_joint(
                        sns.scatterplot, alpha=0.7, edgecolor=".2", linewidth=0.5
@@ -156,7 +170,7 @@ class PlotResults:
                        g.ax_joint.invert_yaxis()

                    g.set_axis_labels(
                        xlabel=f"{format_dict[x_variable]} ({units_dict[x_variable]})",
                        xlabel=f"{format_dict[x_variable]} ({x_unit})",
                        ylabel=f"{format_dict[y_variable]} ({units_dict[y_variable]})",
                    )
                    g.fig.suptitle(title)
+8 −3
Changes for src/geoloop/utils/RunManager.py: 8 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -81,10 +81,15 @@ def sample_parameter_space(config: SingleRunConfig) -> tuple[dict, list[str]]:
        sample_space[param_name] = np.full(n_samples, float(fixed_value))

    # broadcast locked (non-varying) parameters
    # Use list() to ensure each sample gets an independent copy of list parameters,
    # preventing shared-reference issues when optimization modifies values in-place
    # (e.g. r_out[-1] for COAXIAL pipes)
    for param_name in locked_param_names:
        sample_space[param_name] = [
            getattr(config, param_name) for _ in range(n_samples)
        ]
        val = getattr(config, param_name)
        if isinstance(val, list):
            sample_space[param_name] = [list(val) for _ in range(n_samples)]
        else:
            sample_space[param_name] = [val for _ in range(n_samples)]

    return sample_space, varying_parameters

Loading
Loading