--- myst: substitutions: macro: python: 1-5,16-49,52-57,60-61 cpp: 6-11,17-47,50-53,56-57 bloc1: python: "30" cpp: "28" bloc2: python: 35-43 cpp: 33-41 bloc3: python: 45-49,52 cpp: 43-47,50 bloc4: python: 54-57,60-61 cpp: 52-53,56-57 console: python: 2-12 cpp: 5-15 --- (use_cases_macro_calibration_minimisation)= # Macro "**calibrationMinimisationFlowrate1D.{{extension}}**" ## Objective The goal here is to calibrate the parameter $H_l$ within the `flowrate` model, while varying only two inputs ($r_{\omega}$ and $L$). The remaining variables are fixed to the following values: $r=25050$, $T_u=89335$, $T_l=89.55$, $H_u=1050$, $K_{\omega}=10950$. The context of this example has already been presented in [](#calibration_classes_functions_observations_use_case), including the model (implemented here as a C++ function) and the initial lines defining the {{tds}} objects. This macro demonstrates how to apply a simple minimisation approach using a **Relauncher**-based architecture. (use_cases_macro_calibration_minimisation_macro)= ## Macro {{uranie}} {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/calibration/use_cases/" + language + "/calibrationMinimisationFlowrate1D." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + macro[language] + "\n" + "```" }} Apart from the initial lines described in the section [](#calibration_classes_functions_observations_use_case), the key step is to define the starting point of the minimisation. This can be achieved either by calling the `setStartingPoint` method of the `TNlopt` class, or by assigning a default value to the parameter attributes. In this example, it is done as follows: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/calibration/use_cases/" + language + "/calibrationMinimisationFlowrate1D." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc1[language] + "\n" + "```" }} The model is defined (from a `TCIntEval` instance with the three input variables discussed above, in the **correct order**) along with the computation distribution method (sequential). {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/calibration/use_cases/" + language + "/calibrationMinimisationFlowrate1D." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc2[language] + "\n" + "```" }} Once this setup is complete, the calibration object (`TMinimisation`) is created. As explained in [](#calibration_classes_functions_observations_data_and_distance_recommended_distance), the first step is to define the distance function (here the least squares distance) using `setDistance`. This method also specifies the {{tds}} containing the reference data, the names of the reference inputs, and the reference variable against which the model output is compared. Finally, the optimisation algorithm is defined by creating an instance of `TNloptSubplexe`, and the parameters are then estimated. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/calibration/use_cases/" + language + "/calibrationMinimisationFlowrate1D." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc3[language] + "\n" + "```" }} The final part demonstrates how to display the results. Since this method produces a point estimate, only a single value is obtained, which is always shown on the screen, as illustrated in [](#use_cases_macro_calibration_minimisation_console). Another important aspect is to examine the residuals, as discussed in {{metho}}. This is illustrated in {numref}`usecases_calibrationMinimisationFlowrate1D`, which shows the residuals of the *a posteriori* estimates, typically following a normal distribution. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/calibration/use_cases/" + language + "/calibrationMinimisationFlowrate1D." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc4[language] + "\n" + "```" }} (use_cases_macro_calibration_minimisation_console)= ## Console {{ "```{literalinclude} " + parent_dir + "/roottest/build/uranie/doc/calibration/use_cases/" + language + "/calibrationMinimisationFlowrate1D_clean.log" + "\n" + ":language: none\n" + ":lines: " + console[language] + "\n" + "```" }} ## Graph {{ "```{" "figure" "} " + parent_dir + "/roottest/build/uranie/doc/calibration/use_cases/" + language + "/minimisation/calibrationMinimisationFlowrate1D.png\n" ":align: center\n" ":name: usecases_calibrationMinimisationFlowrate1D\n" + figure_scale + "\n" "\n" "Residuals graph of the macro **\"calibrationMinimisationFlowrate1D." + extension + "\"**\n" "```" }}