Journal topic
Wind Energ. Sci., 4, 619–632, 2019
https://doi.org/10.5194/wes-4-619-2019
Wind Energ. Sci., 4, 619–632, 2019
https://doi.org/10.5194/wes-4-619-2019

Research article 12 Nov 2019

Research article | 12 Nov 2019

# Adjoint-based calibration of inlet boundary condition for atmospheric computational fluid dynamics solvers

Adjoint-based calibration of inlet boundary condition for atmospheric computational fluid dynamics solvers
Siamak Akbarzadeh1, Hassan Kassem2, Renko Buhr1, Gerald Steinfeld1, and Bernhard Stoevesandt2 Siamak Akbarzadeh et al.
• 1ForWind, Center for Wind Energy Research, Carl von Ossietzky University Oldenburg, Küpkersweg 70, 26129 Oldenburg, Germany
• 2Fraunhofer Institute for Wind Energy Systems – Fraunhofer IWES, Küpkersweg 70, 26129 Oldenburg, Germany

Abstract

A continuous adjoint solver is developed for calibration of the inlet velocity profile boundary condition (BC) for computational fluid dynamics (CFD) simulations of the neutral atmospheric boundary layer (ABL). The adjoint solver uses interior domain wind speed observations to compute the gradient of a calibration function with respect to inlet velocity speed and wind direction. The solver has been implemented in the open-source CFD package OpenFOAM coupled with the local gradient-based “CONMIN-frcg” solver of the DAKOTA optimization package. The feasibility of the optimizer output is continuously monitored during the calibration process. The inlet flow profile is considered acceptable only if it can be fitted to a logarithmic or power law function with a tolerance of 3 %. Otherwise, the optimization takes the last fitted profile and asks for a new gradient evaluation. The newly developed framework has been applied in two cases, namely the Ishihara case and Kassel domain. By using the measurements over the hill in the Ishihara case, the method was able to predict the velocity profiles upstream and downstream of the hill accurately. For the Kassel domain, despite the complexity of the site, the method managed to achieve the targeted profile within a reasonable number of the solver calls.

1 Introduction

The wind energy industry is growing very fast and a comprehensive site assessment is a key factor in planning, installation and performance of wind farms. As a result, the interaction of the atmospheric boundary layer (ABL) flow and wind turbines is one of the most important aspects of the site assessments for wind farms. Over the last decades with the development of powerful computers the computational fluid dynamics (CFD) has become one of the leading tools for microscale simulation of the wind flow over complex terrains. However, in general, developing algorithms that capture all the physics of such complex flow regimes is an ongoing research in CFD.

In CFD simulations of atmospheric flows the correct boundary conditions (BCs) are often unknown but measurement data (wind speed, wind direction, etc.) within the area of interest is available. Using the measurement data and an inverse analysis, the unknown BCs can be obtained with an optimization algorithm. This approach is called open boundary optimization and has been successfully tried in oceanography and numerical wind prediction (NWP) models . Another approach is to use observations and statistical analysis to calibrate the CFD model parameters (e.g., inflow and turbulence model constants).

The solution to an optimization problem can be found with different methods. However, the methods such as genetic algorithm and evolutionary strategies require a large number of function evaluations which in CFD applications can be computationally very expensive. Alternatively, the gradient-based optimizers (Ruder2016) use the derivative of cost function with respect to the design parameters. Then, the optimal solution can be obtained using the gradient and a relatively less cost function evaluation. Gradient computation with the finite-difference (FD) method is relatively simple. However, for a high number of design parameters it is prohibitively expensive. In the adjoint method, the sensitivity of the objective function can be calculated independently from the number of parameters, and this considerably reduces the cost of computation.

In principle, both methods can be applied to any algorithm and model which is continuously differentiable. However, the manually derived discrete adjoint differentiation of big CFD codes is laborious and error prone. Although, the AD tools can be seen as an interesting solution to this problem, their application to the codes which are written in high-level languages (e.g., C$++$) is still limited in terms of memory requirement and performance. A comparison of these two adjoint approaches can be found here .

The discrete adjoint version of OpenFOAM-based solvers has been presented before . More recently a hybrid approach has also been introduced in which some parts of the code are differentiated by finite difference, and better performance is reported in comparison to the pure discrete adjoint version of the code. Despite all these improvements, the continuous adjoint version of OpenFOAM solvers are still more popular.

The adjoint method has been well applied to different problems in atmospheric science such as wind turbine blade shape optimization , wind-farm control and wind-farm layout optimization . have used the adjoint method and large eddy simulation (LES)-based 4D-Var data assimilation to estimate the turbulent flow field of an atmospheric boundary layer domain from lidar data. Although compared to the Reynolds Averaged Navier–Stokes (RANS) models, the LES can provide more accurate predictions of the flow field, it is still mainly used as a research tool due to its demanding computing power.

The effect of inflow boundary wind speed and its direction are significant parameters in ABL CFD simulation, but they are not often known. The focus of this paper is on the adjoint gradient-based calibration of the inlet velocity profile and inflow wind direction (WD) for a RANS-based ABL flow, which is a very common CFD solver in the wind energy industry, with only a few wind speed measurements from a metrological mast at the site. The available continuous adjoint solver of OpenFOAM CFD tool package (adjointShapeOptimizationFoam), which is for topology optimization of duct flows, is further developed to compute the gradients.

The structure of the paper is as follows: the gradient-based optimization and the theory of the adjoint method are briefly presented in Sect. 2. The derivation of the adjoint equations and its BCs from the primal flow model is explained in Sect. 3. Finally, the numerical results and the conclusions are presented in Sects. 4 and 5.

In gradient-based optimization or calibration, one needs to compute the gradient of a smooth cost function, J, with respect to the design parameters, α, at each design step,

$\begin{array}{}\text{(1)}& {\mathit{\alpha }}^{n+\mathrm{1}}={\mathit{\alpha }}^{n}+\mathbb{A}\left({\mathit{\alpha }}^{n},\left(\frac{\mathrm{d}J}{\mathrm{d}\mathit{\alpha }}\right)\right)={\mathit{\alpha }}^{n}+\left(\mathrm{\Delta }\mathit{\alpha }{\right)}^{n},\end{array}$

where 𝔸 is an optimization algorithm operator that returns a perturbation Δα to the current design αn. The procedure is repeated until a convergence criterion is reached. The design parameters, α, are chosen based on the optimization problem and its parametrization.

In CFD applications, computing the term $\frac{\mathrm{d}J}{\mathrm{d}\mathit{\alpha }}$ includes the differentiation of the steady-state partial differential equation (PDE) governing equation of the flow,

$\begin{array}{}\text{(2)}& \mathbit{R}\left(\mathbit{\psi },\mathit{\alpha }\right)=\mathrm{0}\to \frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}\frac{\partial \mathbit{\psi }}{\partial \mathit{\alpha }}+\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }}=\mathrm{0},\end{array}$

where R is the residual vector of the discretized flow equations that is driven to zero and ψ stands for state variables (velocity, pressure, temperature, etc.). Eq. (2) results in a linear system,

$\begin{array}{}\text{(3)}& \frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}\frac{\partial \mathbit{\psi }}{\partial \mathit{\alpha }}=-\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }},\end{array}$

in which the term $\frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}$ is Jacobian and $\frac{\partial \mathbit{\psi }}{\partial \mathit{\alpha }}$ represents the perturbation of flow fields. Using the chain rule, the total derivative can be then computed by

$\begin{array}{}\text{(4)}& \frac{\mathrm{d}J}{\mathrm{d}\mathit{\alpha }}=\frac{\partial J}{\partial \mathit{\alpha }}+\frac{\partial J}{\partial \mathbit{\psi }}\frac{\partial \mathbit{\psi }}{\partial \mathit{\alpha }}.\end{array}$

Several methods can be used to compute the gradient from Eq. (4). For instance the complex variable technique, which overcomes the problem of choosing step width in the finite-difference method, or the forward mode (tangent linearization) application of algorithmic differentiation (AD). However, all these methods are computationally expensive when the design space is large. This is due the fact that in Eq. (4) the term $\frac{\partial \mathbit{\psi }}{\partial \mathit{\alpha }}$ requires an expensive PDE simulation, which satisfies Eq. (3) for every dimension in the design space, αi. As will be shown in the following, in the adjoint method the sensitivity can be obtained without computing this expensive term.

From Eq. (3) we can write the perturbation term as

$\begin{array}{}\text{(5)}& \frac{\partial \mathbit{\psi }}{\partial \mathit{\alpha }}=-{\left(\frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}\right)}^{-\mathrm{1}}\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }}\end{array}$

$\begin{array}{}\text{(6)}& \begin{array}{rl}\frac{\mathrm{d}J}{\mathrm{d}\mathit{\alpha }}& =\frac{\partial J}{\partial \mathit{\alpha }}-\frac{\partial J}{\partial \mathbit{\psi }}{\left(\frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}\right)}^{-\mathrm{1}}\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }}=\frac{\partial J}{\partial \mathit{\alpha }}\\ & +\left[-\frac{\partial J}{\partial \mathbit{\psi }}{\left(\frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}\right)}^{-\mathrm{1}}\right]\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }}.\end{array}\end{array}$

The terms in the bracket can be identified as the adjoint system of equations from which the adjoint variable, $\stackrel{\mathrm{‾}}{\mathbit{\psi }}$, can be introduced as

$\begin{array}{}\text{(7)}& \begin{array}{rl}& {\stackrel{\mathrm{‾}}{\mathbit{\psi }}}^{T}=-\frac{\partial J}{\partial \mathbit{\psi }}{\left(\frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}\right)}^{-\mathrm{1}}\phantom{\rule{0.25em}{0ex}}\mathrm{or}\\ & {\left(\frac{\partial \mathbit{R}}{\partial \mathbit{\psi }}\right)}^{T}\stackrel{\mathrm{‾}}{\mathbit{\psi }}=-{\left(\frac{\partial J}{\partial \mathbit{\psi }}\right)}^{T}.\end{array}\end{array}$

In this way, instead of solving a PDE simulation for every design variable, the adjoint system of equations needs to be solved only once. As a result, the computational cost of the gradient becomes independent of the number of design parameters :

$\begin{array}{}\text{(8)}& \frac{\mathrm{d}J}{\mathrm{d}\mathit{\alpha }}=\frac{\partial J}{\partial \mathit{\alpha }}+{\stackrel{\mathrm{‾}}{\mathbit{\psi }}}^{T}\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }}.\end{array}$
3 Derivation of the continuous adjoint solver for ABL inflow calibration

## 3.1 Flow model

The ABL flow model for cases of neutral stratification consists of steady-state Reynolds Averaged Navier–Stokes (RANS) for incompressible fluid flows , which results in the following equations for momentum and continuity:

$\begin{array}{}\text{(9)}& & {\left({R}_{\mathrm{1}},{R}_{\mathrm{2}},{R}_{\mathrm{3}}\right)}^{T}=\left(\mathbit{U}\cdot \mathrm{\nabla }\right)\mathbit{U}+\mathrm{\nabla }p-\mathrm{\nabla }\cdot \left(\mathrm{2}{\mathit{\nu }}_{\mathrm{eff}}\mathbf{D}\left(\mathbit{U}\right)\right),\text{(10)}& & {R}_{\mathrm{4}}=-\mathrm{\nabla }\cdot \mathbit{U},\end{array}$

where (R1, R2, R3) and R4 denote the discretized flow equations, R=(R1, R2, R3, R4)T, in Eq. (2). The variables U and p are the state variables velocity vector and modified pressure, νeff stands for the sum of kinematic and turbulent viscosity, and D is the rate of strain tensor, $\mathbf{D}=\frac{\mathrm{1}}{\mathrm{2}}\left(\mathrm{\nabla }\mathbit{U}+\left(\mathrm{\nabla }\mathbit{U}{\right)}^{T}\right)$. Throughout this work, the standard kϵ turbulence model with the addition of a forest model is used.

### 3.1.1 Inflow boundary

The properties of the inflow boundary have an important effect on the solution of the interior domain. With the increasing application of LES, hybrid RANS-LES and direct numerical simulation (DNS) methods, the inflow turbulence generation has become the subject of many research works in recent decades. For a review of such methods and their application in wind energy, we refer to Wu (2017) and . However, due to computational cost, it is still popular in the wind energy industry to use the RANS model with an inflow boundary obtained from either an analytical formula or a one-dimensional (1-D) simulation. The idea of the latter method is to solve a zero-pressure gradient equation for a 1-D domain with periodic boundary conditions in the stream- and span-wise directions :

$\begin{array}{}\text{(11)}& \frac{\partial \stackrel{\mathrm{‾}}{{\mathbit{U}}_{x}^{\prime }{\mathbit{U}}_{z}^{\prime }}}{\partial z}=\mathrm{0},\end{array}$

where x (horizontal) and z (vertical) are the Cartesian coordinates. The inflow profile and its turbulent characteristics are obtained from this 1-D simulation and then are mapped to the 3-D inlet boundary.

### 3.1.2 Forest effect

Forest canopies modify the available free volume of the terrain domain and introduce an explicit drag term to the momentum equation as below:

$\begin{array}{}\text{(12)}& {\mathbit{F}}_{\mathrm{D}}=-\frac{\mathrm{1}}{\mathrm{2}}\mathit{\rho }{C}_{\mathrm{d}}A\left(z\right)|\mathbit{U}|\mathbit{U}\end{array}$

with density ρ, leaf-level canopy drag coefficient Cd and leaf area density A(z). The effects of the forest in the turbulence models such as kϵ for ABL flows have been extensively discussed in the literature and several formulas are presented to make the turbulence model consistent with the modified momentum equation. For more details, the reader may be referred to .

Calibration algorithms seek to maximize the agreement between simulation outputs and measurements. In the context of ABL-based model calibration, the data are often wind speed and direction at one or more locations of a potential wind-farm site. The CFD-based calibration can be formulated as a constrained optimization problem with a scalar objective function:

$\begin{array}{}\text{(13)}& \begin{array}{rl}\mathrm{minimize}& J\left({\mathbit{U}}_{\mathrm{M}},{\mathbit{U}}_{\mathrm{S}},\mathit{\alpha }\right)=\sum _{i=\mathrm{1}}^{k}{\left[{\mathbit{U}}_{{\mathrm{M}}_{i}}-{\mathbit{U}}_{{\mathrm{S}}_{i}}\right]}^{\mathrm{2}};\\ & \mathrm{subject}\phantom{\rule{0.25em}{0ex}}\mathrm{to}\phantom{\rule{0.25em}{0ex}}\mathbit{R}\left(\mathbit{U},p,\mathit{\alpha }\right)=\mathrm{0},\end{array}\end{array}$

where R stands for the spatial residual of the flow equations with U and p the discretized velocity and pressure, respectively. ${\mathbit{U}}_{{\mathrm{M}}_{i}}$ and ${\mathbit{U}}_{{\mathrm{S}}_{i}}$ are the measured and simulated wind velocities at the same location in the domain, respectively. The variable α represents the design variables which are considered to be the velocity at inlet faces of the CFD mesh through this work.

The derivation of adjoint equations as in the preceding section is arguably the most straightforward way to introduce the adjoint equations and understand their advantages. However, the first developments for using the adjoint equations in CFD applications were done using a Lagrange multiplier argument . From this point of view, the inner product of the PDE of flow equations and a new set of variables vanishes the variations of state variables, $\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}$ and $\frac{\partial p}{\partial \mathit{\alpha }}$. By introducing the adjoint variables $\stackrel{\mathrm{‾}}{\mathbit{U}}$ and $\stackrel{\mathrm{‾}}{p}$ for adjoint velocity and adjoint pressure, respectively, ${\stackrel{\mathrm{‾}}{\mathbit{\psi }}}^{T}=\left(\stackrel{\mathrm{‾}}{\mathbit{U}}$, $\stackrel{\mathrm{‾}}{p}\right)$, the cost function can be reformulated to a Lagrange function as

$\begin{array}{}\text{(14)}& \begin{array}{rl}L& :=J+\underset{\mathrm{\Omega }}{\int }\left({\stackrel{\mathrm{‾}}{U}}_{x}{R}_{\mathrm{1}}^{T}+{\stackrel{\mathrm{‾}}{U}}_{y}{R}_{\mathrm{2}}^{T}+{\stackrel{\mathrm{‾}}{U}}_{z}{R}_{\mathrm{3}}^{T}+\stackrel{\mathrm{‾}}{p}{R}_{\mathrm{4}}^{T}\right)d\mathrm{\Omega }\\ & =J+\underset{\mathrm{\Omega }}{\int }\left(\stackrel{\mathrm{‾}}{\mathbit{U}},\stackrel{\mathrm{‾}}{p}\right)\mathbit{R}d\mathrm{\Omega },\end{array}\end{array}$

where ${\stackrel{\mathrm{‾}}{U}}_{x}$, ${\stackrel{\mathrm{‾}}{U}}_{y}$ and ${\stackrel{\mathrm{‾}}{U}}_{z}$ are the adjoint velocity components and Ω is the flow domain. For the sensitivities of the cost function with respect to the design parameters, we have to compute the total variation of L:

$\begin{array}{}\text{(15)}& \begin{array}{rl}\frac{\mathrm{d}L}{\mathrm{d}\mathit{\alpha }}=& \frac{\partial J}{\partial \mathit{\alpha }}+\frac{\partial J}{\partial \mathbit{U}}\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}+\frac{\partial J}{\partial p}\frac{\partial p}{\partial \mathit{\alpha }}+\underset{\mathrm{\Omega }}{\int }\\ & \left[\left(\stackrel{\mathrm{‾}}{\mathbit{U}},\stackrel{\mathrm{‾}}{p}\right)\left(\frac{\partial \mathbit{R}}{\partial \mathbit{U}}\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}+\frac{\partial \mathbit{R}}{\partial p}\frac{\partial p}{\partial \mathit{\alpha }}\right)+\left(\stackrel{\mathrm{‾}}{\mathbit{U}},\stackrel{\mathrm{‾}}{p}\right)\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }}\right]d\mathrm{\Omega }.\end{array}\end{array}$

Choosing the Lagrange multipliers such that the variation with respect to the state variables vanishes, leads to

$\begin{array}{}\text{(16)}& \frac{\partial J}{\partial \mathbit{U}}\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}+\frac{\partial J}{\partial p}\frac{\partial p}{\partial \mathit{\alpha }}+\underset{\mathrm{\Omega }}{\int }\left[\left(\stackrel{\mathrm{‾}}{\mathbit{U}},\stackrel{\mathrm{‾}}{p}\right)\left(\frac{\partial \mathbit{R}}{\partial \mathbit{U}}\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}+\frac{\partial \mathbit{R}}{\partial p}\frac{\partial p}{\partial \mathit{\alpha }}\right)\right]d\mathrm{\Omega }=\mathrm{0}.\end{array}$

Then the sensitivity of the cost function can be given by

$\begin{array}{}\text{(17)}& \frac{\mathrm{d}L}{\mathrm{d}\mathit{\alpha }}=\frac{\partial J}{\partial \mathit{\alpha }}+\underset{\mathrm{\Omega }}{\int }\left(\stackrel{\mathrm{‾}}{\mathbit{U}},\stackrel{\mathrm{‾}}{p}\right)\frac{\partial \mathbit{R}}{\partial \mathit{\alpha }}d\mathrm{\Omega },\end{array}$

which excludes the state variable sensitivities.

The theory presented here is based on the work of , which derives an adjoint solver for topology optimization of duct flows to reduce the pressure loss between inlet and outlet boundaries. A more detailed derivation of the model is given by . By neglecting the turbulent viscosity variation, assuming the “frozen turbulence” hypothesis; replacing the derivative of Eq. (9) with the forest source term; and inserting Eq. (10) into Eq. (16), this gives

$\begin{array}{}\text{(18)}& \begin{array}{rl}\frac{\partial J}{\partial \mathbit{U}}& \frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}+\frac{\partial J}{\partial p}\frac{\partial p}{\partial \mathit{\alpha }}+\underset{\mathrm{\Omega }}{\int }\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \left[\left(\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}\cdot \mathrm{\nabla }\right)\mathbit{U}+\left(\mathbit{U}\cdot \mathrm{\nabla }\right)\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}-\mathrm{\nabla }\right\\ & \cdot \left(\mathrm{2}{\mathit{\nu }}_{\mathrm{eff}}\mathbf{D}\left(\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}\right)\right)+\frac{\mathrm{1}}{\mathrm{2}}{C}_{D}A\left(\left|\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}\right|\mathbit{U}+|\mathbit{U}|\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}\right)]d\mathrm{\Omega }\\ & -\underset{\mathrm{\Omega }}{\int }\stackrel{\mathrm{‾}}{p}\mathrm{\nabla }\cdot \frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}d\mathrm{\Omega }+\underset{\mathrm{\Omega }}{\int }\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathrm{\nabla }\frac{\partial p}{\partial \mathit{\alpha }}d\mathrm{\Omega }=\mathrm{0}.\end{array}\end{array}$

Decomposition of parts into interior domain, Ω, and its boundaries, Γ, leads to reformulation of Eq. (18) as follows

$\begin{array}{}\text{(19)}& \begin{array}{rl}\underset{\mathrm{\Gamma }}{\int }& \left[\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{n}+\frac{\partial {J}_{\mathrm{\Gamma }}}{\partial p}\right]\frac{\partial p}{\partial \mathit{\alpha }}d\mathrm{\Gamma }+\underset{\mathrm{\Gamma }}{\int }\left[\mathbit{n}\left(\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{U}\right)+\stackrel{\mathrm{‾}}{\mathbit{U}}\left(\mathbit{U}\cdot \mathbit{n}\right)\right\\ & +\mathrm{2}{\mathit{\nu }}_{\mathrm{eff}}\mathbit{n}\cdot \mathbf{D}\left(\stackrel{\mathrm{‾}}{\mathbit{U}}\right)-\stackrel{\mathrm{‾}}{p}\mathbit{n}+\frac{\partial {J}_{\mathrm{\Gamma }}}{\partial \mathbit{U}}]\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}d\mathrm{\Gamma }\\ & +\underset{\mathrm{\Gamma }}{\int }\left[-\mathrm{2}{\mathit{\nu }}_{\mathrm{eff}}\mathbit{n}\cdot \mathbf{D}\left(\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}\right)\cdot \stackrel{\mathrm{‾}}{\mathbit{U}}\right]d\mathrm{\Gamma }\\ & +\underset{\mathrm{\Omega }}{\int }\left[-\mathrm{\nabla }\cdot \stackrel{\mathrm{‾}}{\mathbit{U}}+\frac{\partial {J}_{\mathrm{\Omega }}}{\partial p}\right]\frac{\partial p}{\partial \mathit{\alpha }}d\mathrm{\Omega }+\underset{\mathrm{\Omega }}{\int }\left[-\mathrm{\nabla }\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{U}\right\\ & -\left(\mathbit{U}\cdot \mathrm{\nabla }\right)\stackrel{\mathrm{‾}}{\mathbit{U}}-\mathrm{\nabla }\cdot \left(\mathrm{2}{\mathit{\nu }}_{\mathrm{eff}}\mathbf{D}\left(\stackrel{\mathrm{‾}}{\mathbit{U}}\right)\right)+\frac{\mathrm{1}}{\mathrm{2}}{C}_{D}A|\mathbit{U}|\stackrel{\mathrm{‾}}{\mathbit{U}}\\ & +\mathrm{\nabla }\stackrel{\mathrm{‾}}{p}+\frac{\partial {J}_{\mathrm{\Omega }}}{\partial \mathbit{U}}]\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}d\mathrm{\Omega }=\mathrm{0}.\end{array}\end{array}$

JΓ and JΩ, respectively, stand for the part of the cost function which is dependent on the flow state values on the boundary and volume of the domain. Due to the definition of the cost function (Eq. 13), its direct variation comes only from the interior domain $\left(\frac{\partial {J}_{\mathrm{\Gamma }}}{\partial \mathbit{U}}=\mathrm{0},\phantom{\rule{0.25em}{0ex}}\frac{\partial {J}_{\mathrm{\Gamma }}}{\partial p}=\mathrm{0}\right)$. Moreover, it does not have any derivative of the pressure field $\left(\frac{\partial {J}_{\mathrm{\Omega }}}{\partial p}=\mathrm{0}\right)$. The only derivative of the cost function is with respect to the inflow and velocity in the interior of the domain and at the locations where the measurements are available. From the latter we have

$\begin{array}{}\text{(20)}& \frac{\partial {J}_{\mathrm{\Omega }}}{\partial \mathbit{U}}=-\mathrm{2}\left({\mathbit{U}}_{{\mathrm{M}}_{i}}-{\mathbit{U}}_{{\mathrm{S}}_{i}}\right)\phantom{\rule{0.25em}{0ex}}\phantom{\rule{0.25em}{0ex}}\phantom{\rule{0.25em}{0ex}}i=\mathrm{1},\mathrm{2},\phantom{\rule{0.125em}{0ex}}\mathrm{\dots }.\end{array}$

Using Eq. (19) and (20) the adjoint equations can be derived as

$\begin{array}{}\text{(21)}& \begin{array}{rl}-\mathrm{\nabla }\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{U}& -\left(\mathbit{U}\cdot \mathrm{\nabla }\right)\stackrel{\mathrm{‾}}{\mathbit{U}}=-\mathrm{\nabla }\stackrel{\mathrm{‾}}{p}+\mathrm{\nabla }\cdot \left(\mathrm{2}{\mathit{\nu }}_{\mathrm{eff}}\mathbf{D}\left(\stackrel{\mathrm{‾}}{\mathbit{U}}\right)\right)\\ & +\left(\frac{\mathrm{2}}{{\mathit{\omega }}_{i}}\right)\left({\mathbit{U}}_{{\mathrm{M}}_{i}}-{\mathbit{U}}_{{\mathrm{S}}_{i}}\right)-\frac{\mathrm{1}}{\mathrm{2}}{C}_{\mathrm{D}}A|\mathbit{U}|\stackrel{\mathrm{‾}}{\mathbit{U}},\end{array}\text{(22)}& \mathrm{\nabla }\cdot \stackrel{\mathrm{‾}}{\mathbit{U}}=\mathrm{0},\end{array}$

where ωi is the volume of the cell in which the measurement is located.

### 3.2.1 Boundary conditions

The boundary integrals of Eq. (19) can be mathematically reformulated and reduced to

$\begin{array}{}\text{(23)}& \underset{\mathrm{\Gamma }}{\int }\left[\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{n}\right]\frac{\partial p}{\partial \mathit{\alpha }}d\mathrm{\Gamma }=\mathrm{0},\text{(24)}& \begin{array}{rl}\underset{\mathrm{\Gamma }}{\int }& \left[\mathbit{n}\left(\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{U}\right)+{\mathit{\nu }}_{\mathrm{eff}}\left(\mathbit{n}\cdot \mathrm{\nabla }\right)\stackrel{\mathrm{‾}}{\mathbit{U}}-\stackrel{\mathrm{‾}}{p}\mathbit{n}\right]\cdot \frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}d\mathrm{\Gamma }\\ & -\underset{\mathrm{\Gamma }}{\int }\left[{\mathit{\nu }}_{\mathrm{eff}}\left(\mathbit{n}\cdot \mathrm{\nabla }\right)\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}\cdot \stackrel{\mathrm{‾}}{\mathbit{U}}\right]d\mathrm{\Gamma }=\mathrm{0},\end{array}\end{array}$

where n is the unit normal vector from the boundary faces. Except for the inlet, which is the design space, the adjoint BCs should be chosen such that the above equations are held.

Generally, for an ABL CFD domain no-slip wall (zero fixed velocity) and zero-pressure gradient conditions are imposed on the ground. For a wall type of boundary in which $\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}$ is zero, the first integral of Eq. (24) is canceled. Then, the only way to satisfy the conditions,

$\begin{array}{}\text{(25)}& & \stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{n}=\mathrm{0},\text{(26)}& & \left(\mathbit{n}\cdot \mathrm{\nabla }\right)\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}\cdot \stackrel{\mathrm{‾}}{\mathbit{U}}=\mathrm{0},\end{array}$

is to apply a no-slip ($\stackrel{\mathrm{‾}}{\mathbit{U}}=\mathrm{0}$) condition on the ground. No BC can be derived on the ground for the adjoint pressure but consistent with the primal a zero gradient condition is applied.

For the top and outlet boundaries of the domain a zero gradient velocity (($\mathbit{n}\cdot \mathrm{\nabla }\right)\frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}=\mathrm{0}$) and zero fixed pressure (p=0) are the common conditions for the primal system. These conditions fulfill Eq. (23) and cancel the second integral of Eq. (24). The only term that remains is the first term of Eq. (24), which needs to be zeroed out,

$\begin{array}{}\text{(27)}& \left[\mathbit{n}\left(\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{U}\right)+{\mathit{\nu }}_{\mathrm{eff}}\left(\mathbit{n}\cdot \mathrm{\nabla }\right)\stackrel{\mathrm{‾}}{\mathbit{U}}-\stackrel{\mathrm{‾}}{p}\mathbit{n}\right]\cdot \frac{\partial \mathbit{U}}{\partial \mathit{\alpha }}=\mathrm{0}.\end{array}$

After decomposition into tangent and normal components it can be shown that the relations below should hold

$\begin{array}{}\text{(28)}& & \stackrel{\mathrm{‾}}{p}=\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{U}+{U}_{n}{\stackrel{\mathrm{‾}}{U}}_{n}+{\mathit{\nu }}_{\mathrm{eff}}\left(\mathbit{n}\cdot \mathrm{\nabla }\right){\stackrel{\mathrm{‾}}{U}}_{n},\text{(29)}& & \mathrm{0}={U}_{n}{\stackrel{\mathrm{‾}}{U}}_{t}+{\mathit{\nu }}_{\mathrm{eff}}\left(\mathbit{n}\cdot \mathrm{\nabla }\right){\stackrel{\mathrm{‾}}{U}}_{t},\end{array}$

where subscripts n and t represent the normal and in-plane components, respectively. The adjoint BCs can be summarized as

$\begin{array}{}\text{(30)}& \mathrm{ground}\phantom{\rule{0.25em}{0ex}}\left(\mathrm{wall}\right):\phantom{\rule{0.25em}{0ex}}\stackrel{\mathrm{‾}}{\mathbit{U}}=\mathrm{0},\phantom{\rule{0.25em}{0ex}}\phantom{\rule{0.25em}{0ex}}\phantom{\rule{0.25em}{0ex}}\mathbit{n}\cdot \mathrm{\nabla }\stackrel{\mathrm{‾}}{p}=\mathrm{0};\text{(31)}& \begin{array}{rl}\mathrm{top}/\mathrm{outlet}:& \stackrel{\mathrm{‾}}{p}=\stackrel{\mathrm{‾}}{\mathbit{U}}\cdot \mathbit{U}+{U}_{n}{\stackrel{\mathrm{‾}}{U}}_{n}+{\mathit{\nu }}_{\mathrm{eff}}\left(\mathbit{n}\cdot \mathrm{\nabla }\right){\stackrel{\mathrm{‾}}{U}}_{n},\\ & {\stackrel{\mathrm{‾}}{U}}_{t}=\mathrm{0}.\end{array}\end{array}$

It is worth mentioning that the last term of the adjoint pressure, which includes the kinematic viscosity, in implementation is often neglected . Moreover, the adjoint variables at the inlet should not be chosen to zero out the inlet velocity perturbations because the design variables are the inlet velocities. Instead, the zero gradient condition is imposed on the inlet for both adjoint velocity and adjoint pressure to have a well-posed system. Finally, from the integral over the boundary term in Eq. (19) it is clear one needs to evaluate the following expression,

$\begin{array}{}\text{(32)}& \begin{array}{rl}\frac{\partial J}{\partial \mathit{\alpha }}& =\frac{\partial J}{\partial {\mathbit{U}}_{\mathrm{inlet}}}=\mathbit{n}\left({\stackrel{\mathrm{‾}}{\mathbit{U}}}_{\mathrm{inlet}}\cdot {\mathbit{U}}_{\mathrm{inlet}}\right)\\ & +{\stackrel{\mathrm{‾}}{\mathbit{U}}}_{\mathrm{inlet}}\left({\mathbit{U}}_{\mathrm{inlet}}\cdot \mathbit{n}\right)+\mathrm{2}{\mathit{\nu }}_{\mathrm{eff}}\mathbit{n}\cdot \mathbf{D}\left({\stackrel{\mathrm{‾}}{\mathbit{U}}}_{\mathrm{inlet}}\right),\end{array}\end{array}$

to compute the sensitivity.

### 3.2.2 Wind direction effect

As it was mentioned before, in ABL CFD simulations it is common to simulate first a 1-D domain with a periodic boundary to obtain the inflow boundary condition. Then the cell center velocity of the 1-D run is copied directly to its counterpart boundary face in the 3-D domain. As a requirement, the number of cells in the 1-D mesh and faces in the vertical direction of the 3-D inflow boundary should be the same (see Fig. 1). Moreover, and ideally, the face center heights in the 3-D mesh are equal to their counterpart cell height in 1-D. Although, in current work, a circular inflow–outflow boundary is considered, with some small modification in the code the method can also be applied to other boundary shapes.

Figure 1The inflow velocities of each cell from 1-D precursor run (a) are copied to the boundary of the 3-D domain (b), which has a similar number of cells in the vertical direction. Ideally the height of each face in the 3-D domain boundary is exactly the same as its counterpart cell in the 1-D mesh.

The inflow wind direction (WD) effect can be expressed by a rotation angle, θ, which rotates the inflow from its default west-to-east (WD = 270) direction,

$\begin{array}{}\text{(33)}& & \mathrm{WD}=\mathrm{270}{}^{\circ }-\mathit{\theta },\text{(34)}& & {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{x}={\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}\mathrm{cos}\left(\mathit{\theta }\right),\text{(35)}& & {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{y}={\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}\mathrm{sin}\left(\mathit{\theta }\right),\text{(36)}& & {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{z}=\mathrm{0}.\end{array}$

The differentiation of Eqs. (34) and (35) gives

$\begin{array}{}\text{(37)}& \frac{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{x}}{\partial {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}}=\mathrm{cos}\left(\mathit{\theta }\right);\phantom{\rule{0.25em}{0ex}}\frac{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{x}}{\partial \mathit{\theta }}=-{\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}\mathrm{sin}\left(\mathit{\theta }\right);\end{array}$

$\begin{array}{}\text{(38)}& \frac{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{y}}{\partial {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}}=\mathrm{sin}\left(\mathit{\theta }\right);\phantom{\rule{0.25em}{0ex}}\frac{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{y}}{\partial \mathit{\theta }}={\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}\mathrm{cos}\left(\mathit{\theta }\right).\end{array}$

The adjoint solver which was explained in the previous section computes the derivative of the cost function with respect to 3-D inflow velocities at each face of the boundary:

$\begin{array}{}\text{(39)}& \frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{x}}{|}_{i,j};\phantom{\rule{0.25em}{0ex}}\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{y}}{|}_{i,j};\phantom{\rule{0.25em}{0ex}}i=\mathrm{1},\phantom{\rule{0.125em}{0ex}}\mathrm{\dots },\phantom{\rule{0.125em}{0ex}}n;\phantom{\rule{0.25em}{0ex}}j=\mathrm{1},\phantom{\rule{0.125em}{0ex}}\mathrm{\dots },\phantom{\rule{0.125em}{0ex}}m,\end{array}$

where i and j represent the row- and column-wise position of a face on the boundary and the total number of the faces in the 3-D circular boundary is $N=n×m$.

Using the chain rule, one can compute the sensitivity with respect to each cell of the 1-D inflow velocity as follows

$\begin{array}{}\text{(40)}& \begin{array}{rl}\frac{\partial J}{\partial {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}}{|}_{i}& =\left(\sum _{j=\mathrm{1}}^{m}\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{x}}{|}_{i,j}\right)\frac{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{x}}{\partial {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}}\\ & +\left(\sum _{j=\mathrm{1}}^{m}\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{y}}{|}_{i,j}\right)\frac{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{y}}{\partial {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}}\\ & =\left(\sum _{j=\mathrm{1}}^{m}\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{x}}{|}_{i,j}\right)\mathrm{cos}\left(\mathit{\theta }\right)\\ & +\left(\sum _{j=\mathrm{1}}^{m}\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{inlet}}\right)}_{y}}{|}_{i,j}\right)\mathrm{sin}\left(\mathit{\theta }\right).\end{array}\end{array}$

Eq. (40) means the x and y gradient components of the 3-D inflow faces at the same column j are accumulated and then multiplied by cos (θ) and sin (θ), respectively, before being summed. For the sake of clarity, Eq. (40) can be rewritten as

$\begin{array}{}\text{(41)}& \frac{\partial J}{\partial {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}}=\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{3}\text{-}\mathrm{D}}\right)}_{x}}\mathrm{cos}\left(\mathit{\theta }\right)+\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{3}\text{-}\mathrm{D}}\right)}_{y}}\mathrm{sin}\left(\mathit{\theta }\right).\end{array}$

Using the same analogy, it can be shown that the sensitivity with respect to rotation angle can be obtained by

$\begin{array}{}\text{(42)}& \begin{array}{rl}\frac{\partial J}{\partial \mathit{\theta }}& =-\left[\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{3}\text{-}\mathrm{D}}\right)}_{x}}\cdot {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}\right]\mathrm{sin}\left(\mathit{\theta }\right)\\ & +\left[\frac{\partial J}{\partial {\left({\mathbit{U}}_{\mathrm{3}\text{-}\mathrm{D}}\right)}_{y}}\cdot {\mathbit{U}}_{\mathrm{1}\text{-}\mathrm{D}}\right]\mathrm{cos}\left(\mathit{\theta }\right),\end{array}\end{array}$

where the dot sign stands for the inner product of the two vectors.

4 Numerical results

The adjoint solver and Eq. (32) are implemented based on the “simpleFoam” incompressible CFD solver of OpenFOAM-4.1. In this section, first the accuracy of the gradients obtained by the developed solver is tested against the 2nd-order FD method in a simple 3-D domain. Then, the inflow calibration of a real complex terrain is presented. For all the simulations in this work the general roughness length of the domain is z0=0.05 (m) and the turbulent eddies are modeled by standard kϵ model with canopy model by . Moreover, an ABL wall function is used to apply the roughness-related logarithmic law near to the ground, which is consistent with Monin–Obukhov similarity theory .

A cylindrical domain with 1000 m radius and 300 m height is chosen. The mesh of the domain has 209 000 hexahedral cells in which the inflow–outflow boundary has 49 rows and 172 columns and a total number of 8428 faces ($N=\mathrm{49}×\mathrm{172}=\mathrm{8428}$). The topoSet utility of OpenFOAM is used to select a number of cells as forest in a box size of 300 m in x and y and 40 m in z direction. The canopy drag and leaf area density for all forest cells are Cd=0.3 and A=0.0033 m−1, respectively. The operational Reynolds number based on the free-stream velocity, forest area height and air kinematic viscosity is $R{e}_{\mathrm{h}}=\mathrm{4.8}×{\mathrm{10}}^{\mathrm{5}}$.

Figure 2The CFD-simulated velocity obtained from the reference simulation (WD = 270): the general view of the domain including the cubic forest and the velocity field on a plane at the center of the domain, y=0(a). The red line on the plane represents the location of desired target velocity profile (see Fig. 3). The velocity field on a plane at z=45 m above the ground (b).

For the primal CFD simulation of a circular domain the standard “inletOutlet” BC is used which checks if the flow is flowing into the domain or out of it and switches between fixed value and zero gradient, respectively. This BC is further developed to apply the derived adjoint BCs in a similar way and based on the flow direction on the boundary.

The gradient evaluation is carried out for a simulation in which the inflow wind direction is WD = 240. To have some reference wind speeds the terrain is simulated assuming the wind blows from west to east (WD = 270). The domain and the velocity field on the planes y=0 m and z=45 m are shown in Fig. 2. The 1-D inflow boundary and the target velocity profiles in the domain are plotted in Fig. 3. The forest effect can be seen in the flow field and on the wind shear of the profile. Please note that the 30 difference between these two simulations is not the step size for the finite-difference computation. The finite-difference step size for gradient validation of wind direction is 0.3.

Figure 3The 1-D inflow boundary (a) and the velocity profile and its selected target speeds in the domain (b).

The gradients obtained by the developed adjoint solver are plotted against the 2nd-order FD gradients in Fig. 4. In general, the trends of the sensitivity profiles are similar. Moreover, the gradients are in excellent agreement except only for the heights between 50 and 100 m in which the maximum relative error is ϵrel=0.10. This difference can be traced back to grid resolution and the derivation of the adjoint equations and BCs which includes some simplifications such as the assumption of the frozen turbulence.

Figure 4Comparison of the inflow boundary gradients by finite differences (FD) and via the adjoint approach.

The wind direction gradients are tabulated in Table 1. The derivative of calibration cost function with respect to the change in wind direction is much higher than the change in the inflow boundary. Here also, there is a good agreement between the FD and the adjoint gradients and the relative error of wind direction sensitivity is close to that of inflow gradients. This is of course not surprising because it was shown in the previous section the sensitivity with respect to θ is obtained by mathematical operations only after the adjoint gradients are available. That said, the accuracy of the gradients computed by the adjoint solver and their signs show that they can be used for the purpose of the gradient-based calibration.

Figure 5The calibration flowchart of the inflow boundary using the DAKOTA optimization package and the developed adjoint solver.

Table 1Comparison of the wind direction gradients by finite differences (FD) and via the adjoint approach.

## 4.2 Inflow calibration

For the cases, studied in this section, the in-house terrainMesher software of the Fraunhofer IWES is used to generate the mesh. The primal flow field is simulated with an in-house CFD solver . The solver is a customized ABL-based version of the simpleFoam solver in the OpenFOAM package with a modified kϵ turbulence model which behaves like a standard model for the neutral condition.

To optimize the inlet velocity profile, the primal and adjoint solvers are coupled with the DAKOTA optimization package . The local gradient-based “CONMIN-frcg” solver of DAKOTA is used, which is based on the conjugate-gradient algorithm by Fletcher and Reeves . Starting from an initial guess, the algorithm updates the design parameters, αn, using the recurrence of Eq. (1) in which

$\begin{array}{}\text{(43)}& \left(\mathrm{\Delta }\mathit{\alpha }{\right)}^{n}={s}^{n}{\mathbb{D}}^{n}\end{array}$

and the positive step size sn is obtained by a line search, and the directions 𝔻 are generated by the following rules:

$\begin{array}{}\text{(44)}& \begin{array}{rl}{\mathbb{D}}^{n+\mathrm{1}}=& -{g}^{n+\mathrm{1}}+{\mathit{\beta }}^{n}{\mathbb{D}}^{n};\phantom{\rule{0.25em}{0ex}}{g}^{n}={\left[\mathrm{\nabla }J\left({\mathit{\alpha }}^{n}\right)\right]}^{T};\\ & {\mathit{\beta }}^{n}=\frac{{\left|{g}^{n+\mathrm{1}}\right|}^{\mathrm{2}}}{{\left|{g}^{n}\right|}^{\mathrm{2}}};\phantom{\rule{0.25em}{0ex}}{\mathbb{D}}^{\mathrm{0}}=-{g}^{\mathrm{0}}.\end{array}\end{array}$

Figure 5 shows the flow chart of the calibration, in which all the steps are followed sequentially. The optimizer starts with an initial guess (both inlet velocity and WD) and repeatedly asks either for the cost function value or the gradients. The primal and the adjoint solvers provide the required information, whenever it is needed, and this process continues until a certain convergence criterion is satisfied.

As a simplistic method, the inflow boundary of a RANS ABL domain can be represented by an empirical power law function or an analytically obtained logarithmic function, which is based on the Monin–Obukhov similarity theory (MOST) (Foken2006). During optimization, the optimizer may ask for a cost function evaluation with a new inflow boundary, which is highly unrealistic for an ABL domain, leading to poor numerical stability or even divergence. One may assume that the inflow boundary is an analytical empirical function and, instead of the inflow velocities, calibrate the parameters of that function. Having the gradient via adjoint solver and using the chain rule, the gradient of the cost function with respect to these parameters can be easily obtained. However, the inflow boundary of a real 3-D complex terrain is neither a power law nor a logarithmic function and such parametrization may fail.

Figure 6Main dimensions of the test case with 1000 m length in the y direction. The velocity flow field on the plane at the center of the domain, y=0.

Figure 7Optimization history (a) and inlet velocity profile comparison (b).

A simple approach is used in this study. This part is called the feasibility check in the optimization flow chart and is a Python script. First of all, the optimizer output is smoothed to avoid having any spikes in the inflow profile. Then it is checked whether a logarithmic, ${f}_{\mathrm{1}}\left(x\right)=A\mathrm{ln}\left(Bx+C\right)$, or a power law, ${f}_{\mathrm{2}}\left(x\right)=A\left(\frac{x}{B}{\right)}^{C}$, function could be fitted into it. If either of these functions is fitted and its coefficient of determination is above 0.96, the smoothed inflow from optimizer (not the fitted profile!) is accepted for the CFD solver. Otherwise, the optimization takes the last fitted profile and asks for a new gradient evaluation. In this way, the inflow boundary is not necessarily a logarithmic or power law profile, and, moreover, it is not so unrealistic to be problematic for the solver. As an alternative, constraints or a penalization term can be added to the objective function. This will be explored in future works when for instance the inflow turbulence properties are also considered design parameters.

### 4.2.1 Ishihara case

As a case study, an ABL domain with a 3-D hill at the center is considered (see Fig. 6). The hill has the shape $z=h{\mathrm{cos}}^{\mathrm{2}}\left(\sqrt{{x}^{\mathrm{2}}+{y}^{\mathrm{2}}}/\mathrm{2}L\right)$ with h=40 m and L=100 m. The scaled wind tunnel study of the case has been presented by . The domain is meshed with 2×106 hexahedral elements. The roughness value of the domain is set to be z0=0.04 m. The operational Reynolds number based on the free-stream velocity, hill height and air kinematic viscosity is $R{e}_{\mathrm{h}}=\mathrm{1.5}×{\mathrm{10}}^{\mathrm{4}}$.

Using wind tunnel measurements, the x component of the velocity over the hill (Ux) is used for the inflow velocity calibration. The velocity flow field at the center of the domain and the wake behind the hill can be seen in Fig. 6. Both the primal and the adjoint solvers have parallel scalability of OpenFOAM toolbox. The runtime of the adjoint solver is 60 %–70 % of the primal flow simulation, which has 30 min wall-clock time run with 24 CPU cores. It is worth noting that in the adjoint solver there is no adjoint turbulence equation to be solved.

The stopping criterion is such that the absolute error between the measurements and the simulated velocities over the hill is ϵabs<0.1 m s−1. Figure 7 shows the history of optimization and the comparison of inlet velocity profiles. The optimization has converged with 14 primal and 12 adjoint calls. The optimal velocity profile is in good agreement with the experiment. There is a small deviation starting from the height $\frac{z}{h}>\mathrm{2}$. However, the comparison of the normalized velocity profiles over the hill, shown in Fig. 8, confirms that the optimized inlet boundary is able to reproduce the experiment velocity profiles.

Figure 8Normalized vertical profiles of longitudinal velocity component on the central plane of the hill. Uh is the velocity at the hill height in the undisturbed region of the domain between inlet and hill.

Figure 9The cylindrical domain of the Kassel terrain (a) and the velocity field at the site at 40 m perpendicular distance from the terrain's surface points, which is simulated with WD = 213 (b). This simulation was used as the reference for the calibration.

### 4.2.2 Kassel case

For the second case study, the neutral condition of “Kassel Experiment” is considered. The domain, located near Kassel in Germany, is one of the cases of the New European Wind Atlas (NEWA) project . There are two meteorological masts at the site including a 200 m high mast (MM200). The wind rose of the site, provided by NEWA, indicates that most of the time the wind blows from the southwest (SW) to northeast (NE).

The site is represented by a cylindrical domain with 15 km radius and 4 km height (see Fig. 9). The structured mesh is generated with the Fraunhofer IWES in-house software “terrainMesher” with 80 cells in the vertical direction. A mesh independence study is conducted to verify the suitability of a mesh of 7×106 hexahedral elements. The vicinity of the hill (zhill=428 m) where the MM200 mast is installed consists of forested area. The leaf area density of the site is obtained from the airborne lidar data and is provided by the NEWA project .

Although the wind speed measurements of the MM200 mast from the site are available, there is not enough information for wind direction at certain heights. This information is necessary for the adjoint solver in which the difference between the components of the measured and simulated velocities is a force term on the right-hand side of the adjoint momentum equation (Eq. 21). Moreover, in the calibration of the solver with real measurements, it would become difficult to discuss the source of error when there is a discrepancy between the target and the calibrated profiles. This is because, aside from the inflow calibration process, which is the aim of the current study, many other parameters (e.g., turbulence model and the accuracy of forest and ground roughness map) are involved. Instead of using the real measurements of the mast, the velocity profile near to the mast from a reference simulation is considered. The selected wind speeds can be regarded as some pseudo-measurements.

Figure 10Inflow boundary calibration for the Kassel domain; cost function convergence (a), wind direction history (b) and gradients history (c).

Figure 11The target, initial and optimized 1-D inflow velocity (a). The velocity profile over the hill from which the pseudo-measurements are chosen (b).

The initial guess WD is defined as 270, meaning wind blows from west to east. The turbulent properties of the inflow boundary are not part of the design parameters; but instead, in each new flow solver call of the optimization, the turbulent parameters of the kϵ model inside of the domain are initialized with the last converged solution. In this way, the turbulence model parameters are also gradually updated toward the end of the optimization when the inlet boundary velocities have reached their optimum value. The adjoint solver runtime for this case is also 60 %–70 % of the primal solver wall-clock time, which is 33 min with 120 CPU cores.

The convergence criterion is defined such that the optimization stops when the absolute difference between simulated and measured value, ϵabs, at all heights is below a certain value. Figure 10 shows the history of optimization and gradients. The optimization has called for a total number of 41 primal solver runs for cost function evaluation. In addition eight adjoint gradient evaluations were required. The optimization convergence graph shows that there is a spike both in the cost function and the wind direction. This can be explained by the fact that in early iterations the derivative of cost function with respect to the WD is much bigger than with respect to inflow. The optimizer updates the WD based on the first gradient computation. This continues for a few iterations until the cost function value, instead of decreasing, increases. Then the optimizer calls for a new gradient computation. From that point onward both the inlet velocities and the wind direction are gradually updated. The optimum WD is found as 216.

The initial and optimal results are compared in Fig. 11. The calibration is stopped based on a criterion, which is defined as ϵabs<0.2 m s−1. Although there is a very small deviation between target and optimized inflow profiles, the velocity profile near to the MM200 mast is in good agreement with the pseudo-measurements at all five selected heights and its error is well below the accepted threshold. Here a couple of points should also be noted. Firstly, a tighter error criterion would increase the calibration iterations and subsequently the number of CFD solver calls. Secondly, the sensitivity of wind speed at a certain point in the domain with respect to a very small change in the inflow boundary is dependent on many parameters such as terrain complexity, wind direction, CFD model, etc., and cannot be easily generalized.

5 Conclusions

In this paper, it has been shown that the ABL CFD solvers can be calibrated via adjoint-based inlet boundary optimization. Based on the frozen turbulence hypothesis and using the reference wind speeds at certain heights inside of the domain, the adjoint equations and its boundary conditions for such problems are derived. The developed solver has been coupled with the DAKOTA optimization package and applied to two 3-D terrains for a neutral stratification condition: (1) the Ishihara test case and (2) the Kassel case. For the Ishihara test case, the optimal inflow was reached with 14 primal and 12 adjoint solver calls. The calibration of the inflow and its directions for the complex terrain of Kassel was achieved after 41 primal and 8 adjoint solver calls. In both cases, an absolute error between the measurements and the simulated velocities was used as a stopping criterion.

The main conclusion remarks of the study can be summarized as follows. (a) The developed calibration framework and the adjoint solver can be successfully applied to even complex domains. (b) The feasibility check of the optimizer output is crucial. Otherwise, at some point in the calibration process, the requested inflow leads to either poor performance or even complete failure (i.e., divergence) of the CFD solver. (c) The convergence criterion can have a big impact on the total number of solver calls. One possibility is to associate the criterion with the uncertainty of the measurements, which can be explored in future work. (d) The process can be further improved to reduce the number of CFD solver calls. For instance, a quasi-Newton optimizer (e.g., BFGS, the Broyden–Fletcher–Goldfarb–Shanno algorithm) or a better parametrization could be used. (e) The presented adjoint solver has the potential to be further developed by including Coriolis force, turbulence model and thermal stratification.

Data availability
Data availability.

The forested hill Kassel of Rödeser Berg in Germany is one of the cases of the New European Wind Atlas (NEWA) project (https://map.neweuropeanwindatlas.eu/, last access: November 2019). The “Kassel Experiment” data used in this work are available at https://windbench.net/newa-r-deser-berg-2017-blind-test (last access: November 2019).

Author contributions
Author contributions.

SA conceived the presented idea, developed the theory and implemented it. HK generated the mesh and provided the settings for primal flow simulations. RB helped carry out the simulations and post-processing of the results. GS and BS supervised the work. All authors discussed the results and contributed to the final article.

Competing interests
Competing interests.

The authors declare that they have no conflict of interest.

Acknowledgements
Acknowledgements.

The work presented in this paper was part of the ETESIAN (FKZ 0324000D) project. The ETESIAN project was funded by the German Federal Ministry for Economic Affairs and Energy due to a decision of the German Bundestag. Moreover, the Kassel domain, which was used for the numerical results, is a test case from the NEWA project. The NEWA project was funded by the German Federal Ministry for Economic Affairs and Energy (ref. no. 0325832A/B) on the basis of a decision by the German Bundestag with further financial support from NEWA ERA-NET Plus, topic FP7-ENERGY.2013.10.1.2. The simulations were performed at the high-performance computing cluster EDDY, located at the University of Oldenburg (Germany), and funded by the Federal Ministry for Economic Affairs and Energy (Bundesministerium für Wirtschaft und Energie) under grant number 0324005.

Financial support
Financial support.

This research has been supported by the German Federal Ministry for Economic Affairs and Energy (grant nos. FKZ0324000D, 0324005 and 0325832A/B) and the German Bundestag with further financial support from NEWA ERA-NET Plus (grant no. FP7-ENERGY.2013.10.1.2).

Review statement
Review statement.

This paper was edited by Raúl Bayoán Cal and reviewed by four anonymous referees.

References

Adams, B. M., Ebeida, M. S., Eldred, M. S., Geraci, G., Jakeman, J. D., Maupin, K. A., Monschke, J. A., Swiler, L. P., Stephens, J. A., Vigil, D. M., and Wildey, T. M.: DAKOTA, a multilevel parallel object-oriented framework for design optimization, parameter estimation, uncertainty quantification, and sensitivity analysis, Tech. rep., Sandia Technical Report SAND2014-4633, Sandia National Laboratories, Albuquerque, NM, 2017. a

Bauweraerts, P. and Meyers, J.: Towards an adjoint based 4D-Var state estimation for turbulent flow, J. Phys.: Conf. Ser., 1037, 072055, https://doi.org/10.1088/1742-6596/1037/7/072055, 2018. a

Chang, C.-Y., Schmidt, J., Dörenkämper, M., and Stoevesandt, B.: A consistent steady state CFD simulation method for stratified atmospheric boundary layer flows, J. Wind Eng. Indust. Aerodynam., 172, 55–67, https://doi.org/10.1016/j.jweia.2017.10.003, 2018. a, b, c

Chen, H., Miao, C., and Lv, X.: Estimation of open boundary conditions for an internal tidal model with adjoint method: a comparative study on optimization methods, Math. Probl. Eng., https://doi.org/10.1155/2013/802136, 2013. a

Davis, L.: Handbook of genetic algorithms, Van Nostrand Reinhold, New York, NY, 1991. a

Dhert, T., Ashuri, T., and Martins, J. R.: Aerodynamic shape optimization of wind turbine blades using a Reynolds-averaged Navier–Stokes model and an adjoint method, Wind Energy, 20, 909–926, https://doi.org/10.1002/we.2070, 2017. a

Dörenkämper, M.: NEWA-Rödeser Berg 2017-Blind Test, Data Source (ALS data): Hessische Verwaltung für Bodenmanagement und Geoinformation, availabl e at: https://windbench.net/newa-r-deser-berg-2017-blind-test/, last access: 9 September 2018. a

EU-ERA-NET: The New European Wind Atlas (NEWA) project, available at: http://www.neweuropeanwindatlas.eu/, last access: 9 September 2018. a

Foken, T.: 50 years of the Monin–Obukhov similarity theory, Bound.-Lay. Meteorol., 119, 431–447, https://doi.org/10.1007/s10546-006-9048-6, 2006. a

Giles, M. B. and Pierce, N. A.: An introduction to the adjoint approach to design, Flow Turbul. Combust., 65, 393–415, https://doi.org/10.1023/A:1011430410075, 2000. a, b

Giles, M. B., Duta, M. C., Müller, J.-D., and Pierce, N. A.: Algorithm developments for discrete adjoint methods, AIAA J., 41, 198–205, https://doi.org/10.2514/2.1961, 2003. a

Glover, N., Guillas, S., and Malki-Epshtein, L.: Statistical calibration of CFD modelling for street canyon flows, in: Proceedings of Building Simulation 2011: 12th Conference of International Building Performance Simulation Association, 14–16 November 2011, Sydney, Australia, 1513–1520, 2011. a

Goit, J., Munters, W., and Meyers, J.: Optimal coordinated control of power extraction in LES of a wind farm with entrance effects, Energies, 9, 29, https://doi.org/10.3390/en9010029, 2016. a

Griewank, A. and Walther, A.: Evaluating derivatives: principles and techniques of algorithmic differentiation, SIAM, Philadelphia, PA, 2008. a

Hager, W. W. and Zhang, H.: A survey of nonlinear conjugate gradient methods, Pacif. J. Optimiz., 2, 35–58, 2006. a

He, P., Mader, C. A., Martins, J. R., and Maki, K. J.: An aerodynamic design optimization framework using a discrete adjoint approach with OpenFOAM, Comput. Fluids, 168, 285–303, https://doi.org/10.1016/j.compfluid.2018.04.012, 2018. a

Hinterberger, C. and Olesen, M.: Industrial application of continuous adjoint flow solvers for the optimization of automotive exhaust systems, CFD & Optimization, Antalya, Turkey, 2011. a

Hinze, M., Pinnau, R., Ulbrich, M., and Ulbrich, S.: Optimization with PDE constraints, in: vol. 23, Springer Science & Business Media, New York, NY, 2008. a

Ishihara, T., Hibi, K., and Oikawa, S.: A wind tunnel study of turbulent flow over a three-dimensional steep hill, J. Wind Eng. Indust. Aerodynam., 83, 95–107, https://doi.org/10.1016/S0167-6105(99)00064-1, 1999. a, b

Jameson, A.: Aerodynamic Design via Control Theory, J. Scient. Comput., 3, 233–260, https://doi.org/10.1007/BF01061285, 1988. a

Jameson, A., Martinelli, L., and Pierce, N.: Optimum Aerodynamic Design using the Navier–Stokes equations, Theor. Comput. Fluid Dynam., 10, 213–237, https://doi.org/10.1007/s001620050060, 1998. a

Kämmerer, S., Mayer, J., Paffrath, M., Wever, U., and Jung, A.: Three-dimensional optimization of turbomachinery bladings using sensitivity analysis, ASME Turbo Expo: Power for Land, Sea, and Air, 6, 1093–1101, https://doi.org/10.1115/GT2003-38037, 2003. a

King, R. N., Dykes, K., Graf, P., and Hamlington, P. E.: Optimization of wind plant layouts using an adjoint approach, Wind Energ. Sci., 2, 115–131, https://doi.org/10.5194/wes-2-115-2017, 2017. a

Li, H.-D., He, L., Li, Y., and Wells, R.: Blading aerodynamics design optimization with mechanical and aeromechanical constraints, ASME Turbo Expo: Power for Land, Sea, and Air, 6, 1319–1328, https://doi.org/10.1115/GT2006-90503, 2006. a

Liu, J., Chen, J., Black, T., and Novak, M.: Eε modelling of turbulent air flow downwind of a model forest edge, Bound.-Lay. Meteorol., 77, 21–44, https://doi.org/10.1007/BF00121857, 1996. a

Lopes da Costa, J.: Atmospheric Flow Over Forested and Non-Forested Complex Terrain, PhD thesis, University of Porto, Porto, 2007. a

Mavriplis, D. J.: Discrete adjoint-based approach for optimization problems on three-dimensional unstructured meshes, AIAA J., 45, 741–750, https://doi.org/10.2514/1.22743, 2007. a

Michalewicz, Z.: Evolution strategies and other methods, in: Genetic algorithms + data structures = evolution programs, 159–177, Springer, Berlin, 1996. a

Munters, W. and Meyers, J.: An optimal control framework for dynamic induction control of wind farms and their interaction with the atmospheric boundary layer, Philos. T. Roy. Soc. A, 375, 20160100, https://doi.org/10.1098/rsta.2016.0100, 2017. a

Nadarajah, S. and Jameson, A.: A Comparison of the Continuous and Discrete AIAA CP-00-0667, Adjoint Approach to Automatic Aerodynamic Optimization, Reno, NV, 2000. a

Nadarajah, S. and Jameson, A.: Studies Of The Continuous And Discrete Adjoint Approaches To Viscous Automatic Aerodynamic Shape Optimization, in: 15th AIAA Computational Fluid Dynamics Conference, AIAA, Anaheim, CA, p. 2530, 2001. a

Nielsen, E. J., Diskin, B., and Yamaleev, N. K.: Discrete adjoint-based design optimization of unsteady turbulent flows on dynamic unstructured grids, AIAA J., 48, 1195, https://doi.org/10.2514/1.J050035, 2010. a

Nilsson, U., Lindblad, D., and Petit, O.: Description of adjointShapeOptimizationFoam and how to implement new objective functions, in: course at Chalmers University of Technology, Enero, 2014. a

Othmer, C.: A continuous adjoint formulation for the computation of topological and surface sensitivities of ducted flows, Int. J. Numer. Meth. Fluids, 58, 861–877, https://doi.org/10.1002/fld.1770, 2008. a

Othmer, C. and Grahs, T.: Approaches to fluid dynamic optimization in the car development process, in: Eurogen, FLM, Munich, 2005. a

Othmer, C., Kaminski, T., and Giering, R.: Computation of topological sensitivities in fluid dynamics: cost function versatility, in: Eccomas CFD 2006, edited by: Wesseling, P., Oñate, E., and Périaux, J., Citeseer, Delft, 2006. a

Pironneau, O.: On Optimum Design in Fluid Mechanics, J. Fluid Mech., 64, 97–110, https://doi.org/10.1017/S0022112074002023, 1974. a

Rebollo, T. C. and Lewandowski, R.: Mathematical and numerical foundations of turbulence models and applications, Springer, New York, NY, 2014. a

Reeves, C. M. and Fletcher, R.: Function minimization by conjugate gradients, Comput. J., 7, 149–154, https://doi.org/10.1093/comjnl/7.2.149, 1964. a

Ruder, S.: An overview of gradient descent optimization algorithms, arXiv preprint arXiv:1609.04747, 2016. a

Schneiderbauer, S. and Pirker, S.: Determination of open boundary conditions for computational fluid dynamics (CFD) from interior observations, Appl. Math. Model., 35, 763–780, https://doi.org/10.1016/j.apm.2010.07.032, 2011. a

Seiler, U.: Estimation of open boundary conditions with the adjoint method, J. Geophys. Res.-Oceans, 98, 22855–22870, https://doi.org/10.1029/93JC02376, 1993. a

Stevens, R. J. and Meneveau, C.: Flow structure and turbulence in wind farms, Annu. Rev. Fluid Mech., 49, 311–339, https://doi.org/10.1146/annurev-fluid-010816-060206, 2017. a

Towara, M. and Naumann, U.: A Discrete Adjoint Model for OpenFOAM, Procedia Comput. Sci., 18, 429–438, https://doi.org/10.1016/j.procs.2013.05.206, 2013.  a

Towara, M., Schanen, M., and Naumann, U.: Mpi-parallel discrete adjoint openfoam, Procedia Comput. Sci., 51, 19–28, https://doi.org/10.1016/j.procs.2015.05.181, 2015. a

Vali, M., Petrović, V., Boersma, S., van Wingerden, J.-W., Pao, L. Y., and Kühn, M.: Adjoint-based model predictive control for optimal energy extraction in waked wind farms, Control Eng. Pract., 84, 48–62, https://doi.org/10.1016/j.conengprac.2018.11.005, 2019. a

Wu, X.: Inflow turbulence generation methods, Annu. Rev. Fluid Mech., 49, 23–49, https://doi.org/10.1146/annurev-fluid-010816-060322, 2017. a