HomeFeaturesExamplesTutorialsHelpTheoryVerificationPricingContact
BoreTherm / TutorialsTutorial 07 / 19
Workflow and theory · Ground data & uncertainty

Monte Carlo

How uncertain inputs become a distribution of the borehole length, how BoreTherm draws the samples, what it calculates for each one, and how to read the percentiles and the sensitivity ranking for a design. The numbers are those of the example project: an office building with a heat pump on a field of 16 boreholes (4 × 4, 6 m apart, 150 m), monthly loads of 200 MWh heating, 45 MWh cooling and 8 MWh hot water a year, simulated over 25 years, with 100 samples.

01 / The one idea

The one idea: a length with a confidence level

A normal design (Calculation › Size borehole length) takes every input as exact and gives one length H: the borehole length at which the mean fluid temperature Tf (the mean of the inlet and outlet temperature of the borehole fluid) just reaches its limits. But the ground conductivity λ, the undisturbed temperature and the loads are known only within a range. Monte Carlo gives each uncertain input a probability distribution, draws many input combinations, sizes the borehole for each of them, and looks at the spread of the results.

Uncertain inputs (the example)Ground conductivity λNormal, mean 2.6, sd 0.3Heat capacity CUniform 2.0 to 2.6Surface temperature TsNormal, mean 9.0, sd 0.5Heating energy factorTriangular 0.90 / 1.00 / 1.15Draw N samples100 × 4 valuesLatin hypercube, seed 1Size every samplethe required length H(Size borehole length)Required length H [m]: 100 values110120130140150160170180P95166.3 mP50 145.1base 143.7
The example: four uncertain inputs, 100 samples, one sizing per sample. P95, the 95th percentile, is the length that is enough in 95 % of the sampled combinations (P50, the median, in half of them); base is the length that Size borehole length gives with every input at its project value.
Inverse transformx = F−1(u)
Latin hypercubeuij = (πj(i) + vij) / N
Design lengthH95 = P95(H)
Sensitivityρs of the ranks

F is the cumulative distribution function of an input, u is uniform on (0, 1), πj is a random permutation of the N strata of input j and vij a uniform number in [0, 1). ρs is Spearman’s rank correlation between an input and the result over all samples (section 4). The confidence refers only to the inputs given as uncertain, with the distributions given. Everything else is taken as exact.

02 / The workflow

The workflow

The first choice is the mode. It decides what is calculated for each sample: Size mode sizes the length as Size borehole length does; Simulate mode keeps the length and calculates Tf over the period as Calculation › Calculate does. The limits are the lowest and highest Tf allowed (Tf,min, Tf,max); Hmin–Hmax is the range in which the length is searched. A thermal response test (TRT) measures λ on site.

Set up the design as usualground, loads, limits, sizing range Hmin to HmaxIs the borehole lengthalready fixed?noyesSize mode (default)each sample: the required length Hresult: P50, P95 of H and the total lengthApply H at 95 % confidence → the projectSimulate modeeach sample: Tf at the current lengthresult: share of runs within the limitsand the spread of Tf min / maxBoth modes rank the inputs by Spearman ρ: the top input is the one worth measuring better (a TRT for λ).
Size mode answers “how long must the boreholes be?”. Simulate mode answers “how likely is it that this field stays within the limits?”.

In the program, Monte Carlo is started from Tools › Monte Carlo… and the results appear under Advanced analysis › Studies & uncertainty › Monte Carlo.

Design pagesground, loads, limits:the base valuesMonte Carlo… dialoginputs, distributions,samples, seed, modeRunevery sample on a copyof the project, parallelMonte Carlo pageStudies & uncertainty(Advanced analysis)SummaryHistogramSensitivityConvergenceScatterRunsmain pathtabs of the results pageApply H at 95 % confidence (Size mode): sets the project’s borehole length to P95 of HThe same setup runs from the command line: boretherm-cli montecarlo <project> (stored in the project file).
The dialog stores its setup in the project; the results page shows the statistics. Apply H at 95 % confidence is the only step that changes the design (unequal lengths are scaled to this mean).
  • Dialog: the uncertain inputs (any registered input: ground, layers, borehole, grout, pipes, flow, fluid, load multipliers, SPF, limits), their distribution (normal, log-normal, uniform, triangular) with optional truncation, the number of samples (2 to 100 000), the seed, the sampling method, the mode and optional rank correlations.
  • Results page: Summary (statistics table and the Spearman ρ of each input), Histogram, Sensitivity, Convergence (statistics of the first n samples), Scatter (one input against the result) and Runs (every run, CSV export).
03 / How the calculation works

How the calculation works

1 Check the setupknown ids, valid distributions,truncation, correlation matrix2 Draw the sample matrixN × k, one generator (seed),serial, input by input3 Correlate (optional)Iman–Conover reorders columns;each input keeps its values6 Statisticsmean, sd, P5…P95, histogram,Spearman ρ, share within limits5 Sort the runsfailed (error) and, in Size mode,not sized in Hmin–Hmax: excluded4 Run every sampleproject copy + sampled values;Size or Simulate, in parallelSteps 1–3 and 6 are serial, step 4 is parallel: the result does not depend on the number of threads.
Monte Carlo adds no new physics: every sample is an ordinary Size borehole length or Calculate run of a modified copy of the project.
  1. Check. Unknown or repeated ids, invalid parameters (sd < 0, min > max, mode outside the triangle), truncation bounds that exclude the distribution, and a correlation matrix that is not positive definite stop the run before anything is drawn.
  2. Draw. One random generator (64-bit Mersenne twister) started with the seed fills the N × k matrix input by input. Each value is x = F−1(u). With truncation to [lo, hi], u is first mapped to F(lo) + u · (F(hi) − F(lo)): the truncated distribution is sampled exactly, with no rejection loop. The same seed and setup give the same matrix on every PC; adding an input does not change the columns before it.
  3. Correlate. With rank correlations (Iman–Conover 1982) each column is reordered so that the ranks follow the target. The values of each input, and so its distribution, do not change; only their pairing does.
  4. Run. Each sample is applied to a copy of the project through the input registry (values outside the input’s sanity bounds make that run fail). Size mode sizes the length with the project’s sizing options; Simulate mode simulates at the current lengths and reuses g-functions (the dimensionless temperature response of the field to a constant heat rate) between samples with the same field.
  5. Sort. A run that throws an error is failed. In Size mode a run that cannot be sized within Hmin–Hmax is not sized: its length would be clipped at Hmax, which is not a required length. Both are counted and left out of the statistics.
  6. Statistics over the remaining runs (section 5).
04 / Sampling and reading the percentiles

Sampling and reading the percentiles

Inverse transform: u in 10 strata → λ0.00.51.02.02.53.03.5λ [W/(m K)], truncated at 1.5 and 4.0u = F(λ)Randomu of input 1Latin hypercubeu of input 1LHS: exactly one sample in every row and every column.
Left: Latin hypercube cuts u into N equally likely strata and takes one value in each, so the tails of every input are always visited. Right: with plain random sampling some strata stay empty and others get two samples.

A percentile is read from the sorted results. P95 of H is the length that 95 % of the runs did not need to exceed. With N runs it is an estimate, and the tail is the least certain part: the statistics must settle as N grows.

Statistics of the first n samples0255075100130140150160170P95P50 (solid) and mean (dashed)number of samples nH [m]Each run: λ against the required H2.02.42.83.2120140160180sampled λ [W/(m K)]H [m]
Left: the Convergence tab: mean, P50 and P95 of the first n samples. The mean and P50 settle early; P95 still moves at n = 100. Right: the Scatter tab: λ alone explains most of the spread of H; the scatter around the trend comes from the other three inputs.
How sure is P95 with 100 samples? P95 is an order statistic. The true 95 % quantile lies between the 90th and the 100th of the 100 sorted lengths with 98.3 % probability (binomial distribution, BoreTherm theory manual): between 158.7 m and 171.5 m. 100 samples show the method; for a design length use about 1000 (the interval then shrinks to about P93.6–P96.4).

The sensitivity ranking uses Spearman’s rank correlation between each input and the result, with all inputs varying together. |ρ| near 1 means the input dominates; the sign gives the direction. When the result is close to additive in the inputs, the ρ² add up to about 1 (here: 0.97).

Spearman rank correlation of each input with the required length H−1.0−0.50.00.51.0Ground conductivity λ−0.77Surface temperature Ts−0.43Heating energy factor0.41Heat capacity C−0.17larger input → shorter boreholeslarger input → longer boreholes
Ground conductivity is the input that matters: measuring it (a thermal response test) narrows the length distribution most. The heat capacity hardly matters for this field.
05 / How each result is derived

How each result is derived

ResultHow BoreTherm derives itExample
H at 95 % confidence (P95 of H)type-7 percentile of the 100 sized lengths: h = 0.95 · (N − 1) = 94.05 → x(94) + 0.05 · (x(95) − x(94)), 0-based166.3 + 0.05 · (167.1 − 166.3) = 166.3 m
Median P50 and P5the same rule at p = 50 and 5145.1 m and 130.4 m
Mean and standard deviationover the runs summarised; sd with n − 1145.2 m ± 10.9 m
Total lengththe same statistics of Nb · H (16 boreholes)P50 2322 m, P95 2661 m
Tf,max and Tf,minextremes of the sizing criterion in every sized runTf,max P95 17.3 °C (limit 20 °C); Tf,min −3.00 °C to −2.99 °C
Share within the limitsSize mode: runs sized inside Hmin–Hmax; Simulate mode: runs whose limits check passes100 %
Failed / not sizeda run error, or (Size) not sized within Hmin–Hmax: left out of every statistic0 / 0
Spearman ρ (sensitivity)Pearson correlation of the ranks of an input and of H over the runs summarisedλ −0.77, Ts −0.43
HistogramFreedman–Diaconis width 2 · IQR · n−1/3 (IQR = P75 − P25), equal bins from min to max2 · 12.56 · 100−1/3 = 5.41 m → 11 bins

In Size mode every sized run ends with its binding limit just met: here Tf,min sits at the −3 °C limit in all 100 runs (within the sizing tolerance). The spread is in the length, not in the temperature, so the Spearman ρ against Tf,min carries no information in this mode.

06 / The example in numbers

The example in numbers

Uncertain inputUnitProject valueDistributionTruncationρ with H
Ground conductivity λW/(m K)2.6Normal, mean 2.6, sd 0.31.5 to 4.0−0.77
Ground heat capacity CMJ/(m³ K)2.2Uniform 2.0 to 2.6none−0.17
Surface temperature Ts°C9.0Normal, mean 9.0, sd 0.5none−0.43
Heating energy multiplier–1.00Triangular 0.90 / 1.00 / 1.15none0.41

100 Latin-hypercube samples, seed 1, Size mode, Hmin–Hmax 20–300 m, limits −3 °C / 20 °C. 0 runs failed, 0 were not sized. The ordinary sizing with every input at its project value gives 143.7 m. The median of the samples is 145.1 m, close to it; P95 is 166.3 m, 22.6 m (+16 %) more. That difference is the price of the stated uncertainty at 95 % confidence: 362 m of drilling for the 16 boreholes.

07 / Limits to keep in mind

Limits to keep in mind

  • The result is only as good as the distributions. Base them on data: a TRT with its confidence interval for λ, measured temperatures for Ts, the uncertainty of the load forecast.
  • Each sample uses one value per input for the whole field (homogeneous ground). Spatial scatter between boreholes is not sampled.
  • Inputs are independent unless you give rank correlations. Correlated inputs share their ρ: read them together.
  • Runs that fail or are not sized are left out. If “not sized within Hmax” appears, the percentiles describe only the sized runs and understate the length: widen Hmin–Hmax and run again.
  • The tails need samples: 100 for a first look, about 1000 for P90/P95 that are used as a design length. The Convergence tab shows when the curves are flat.
  • Monte Carlo always uses the analytic (g-function) model of the design, also when the project has a 3D / FEM analysis.

Numbers calculated with BoreTherm. Theory: BoreTherm theory manual.