#!/bin/bash cd "${0%/*}" || exit # Run from this directory . ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions #------------------------------------------------------------------------------ # Benchmark dataset: # Arnqvist, J., Segalini, A., Dellwik, E., & Bergström, H. (2015). # Wind statistics from a forested landscape. # Boundary-Layer Meteorology, 156(1), 53-71. # DOI:10.1007/s10546-015-0016-x #------------------------------------------------------------------------------ # Simple linear interpolation on an ascending table linearInterp() { inpFile=$1 zRef=$2 yi=($(awk -v zRef="$zRef" ' BEGIN{ x1=0; y1=0; x2=$1; y2=$2; } { if((x1 < zRef) && (x2 < zRef) && (getline != 0)) { x1=x2; y1=y2; x2=$1; y2=$2 } } END { yi = (y2-y1)/(x2-x1)*(zRef-x1) + y1; print yi } ' $inpFile)) echo "$yi" } plotU() { timeDir=$1 treeH=$2 zRef=$3 smple=$4 shift 4 declare -a inps=("${!1}") echo " Plotting the ground-normal normalised " echo " streamwise flow speed profile." for i in "${!inps[@]}" do inp="results/${inps[$i]}/$timeDir/$smple" echo $inp # Store the ground-normal height z=($(awk '{ printf "%.16f\n", $1 }' $inp)) # Compute velocity magnitude by excluding the ground-normal component magU=($(awk ' { mag = sqrt($2*$2 + $3*$3); printf "%.16f\n", mag }' $inp)) file="z-magU-$i.dat" [ ! -f $file ] && for ((j = 0; j < "${#magU[@]}"; j++)) \ do printf "%.16f %.16f\n" "${z[$j]}" "${magU[$j]}" \ >> $file; done # Find velocity magnitude at zRef height by linear interpolation uRef=$(linearInterp "$file" "$zRef") # Find z normalised by the reference tree height zNorm=($(awk -v treeH="$treeH" ' { zNorm = $1/treeH; printf "%.16f\n", zNorm }' $file)) # Find U normalised by uRef uNorm=($(awk -v uRef="$uRef" ' { uNorm = $2/uRef; printf "%.16f\n", uNorm }' $file)) fil="zNorm-uNorm-$i.dat" [ ! -f $fil ] && for ((j = 0; j < "${#zNorm[@]}"; j++)) \ do printf "%.16f %.16f\n" "${zNorm[$j]}" "${uNorm[$j]}" \ >> $fil; done done outName="plots/uNorm-zNorm.png" gnuplot<> $file; done # Find k at zRef height by linear interpolation kRef=$(linearInterp "$file" "$zRef") # Find z normalised by the reference tree height zNorm=($(awk -v treeH="$treeH" ' { zNorm = $1/treeH; printf "%.16f\n", zNorm }' $file)) # Find k normalised by kRef kNorm=($(awk -v kRef="$kRef" ' { kNorm = $2/kRef; printf "%.16f\n", kNorm }' $file)) fil="zNorm-kNorm-$i.dat" [ ! -f $fil ] && for ((j = 0; j < "${#zNorm[@]}"; j++)) \ do printf "%.16f %.16f\n" "${zNorm[$j]}" "${kNorm[$j]}" \ >> $fil; done done outName="plots/kNorm-zNorm.png" gnuplot<> $file; done # Find the Obukhov length at zRef height by linear interpolation OLRef=$(linearInterp "$file" "$zRef") echo "${inps[$i]} = $OLRef" >> "plots/ObukhovLength.dat" done rm -f z-OL-*.dat } plotVeer() { timeDir=$1 treeH=$2 zRef=$3 smple=$4 shift 4 declare -a inps=("${!1}") echo " Plotting the ground-normal normalised veer profile." for i in "${!inps[@]}" do inp="results/${inps[$i]}/$timeDir/$smple" echo $inp # Store the ground-normal height z=($(awk '{ printf "%.16f\n", $1 }' $inp)) # Store streamwise and spanwise velocity components u=($(awk '{ printf "%.16f\n", $2 }' $inp)) v=($(awk '{ printf "%.16f\n", $3 }' $inp)) fileu="z-u-$i.dat" [ ! -f $fileu ] && for ((j = 0; j < "${#z[@]}"; j++)) \ do printf "%.16f %.16f\n" "${z[$j]}" "${u[$j]}" \ >> $fileu; done filev="z-v-$i.dat" [ ! -f $filev ] && for ((j = 0; j < "${#z[@]}"; j++)) \ do printf "%.16f %.16f\n" "${z[$j]}" "${v[$j]}" \ >> $filev; done # Find u and v at zRef height by linear interpolation uRef=$(linearInterp "$fileu" "$zRef") vRef=$(linearInterp "$filev" "$zRef") # Find z normalised by the reference tree height zNorm=($(awk -v treeH="$treeH" ' { zNorm = $1/treeH; printf "%.16f\n", zNorm }' $fileu)) # Find veer veer=($(awk -v uRef="$uRef" -v vRef="$vRef" ' { x = $2/sqrt($2*$2 + $3*$3); xR = uRef/sqrt(uRef*uRef + vRef*vRef); veer = -1*(atan2(sqrt(1 - x*x), x) - atan2(sqrt(1 - xR*xR), xR))*180/atan2(0, -1); printf "%.16f\n", veer }' $inp)) fil="zNorm-veer-$i.dat" [ ! -f $fil ] && for ((j = 0; j < "${#zNorm[@]}"; j++)) \ do printf "%.16f %.16f\n" "${zNorm[$j]}" "${veer[$j]}" \ >> $fil; done done outName="plots/veer-zNorm.png" gnuplot</dev/null || { echo "gnuplot not found - skipping graph creation" 1>&2 exit 1 } # Requires awk command -v awk >/dev/null || { echo "awk not found - skipping graph creation" 1>&2 exit 1 } # The latestTime in postProcessing/samples timeDir=$(foamListTimes -case results/veryStable/postProcessing/samples \ -latestTime 2>/dev/null) [ -n "$timeDir" ] || { echo "No results found in postProcessing - skipping graph creation" 1>&2 exit 1 } timeDir="postProcessing/samples/$timeDir" # Settings declare -a stability stability[0]="veryStable" stability[1]="stable" stability[2]="slightlyStable" stability[3]="neutral" stability[4]="slightlyUnstable" stability[5]="unstable" sample1="lineZ1_U.xy" sample2="lineZ1_ObukhovLength_T_Ustar_k_p_rgh.xy" treeHeight=20 zRef=40 # Postprocessing mkdir -p plots plotU $timeDir $treeHeight $zRef $sample1 stability[@] plotK $timeDir $treeHeight $zRef $sample2 stability[@] printObukhovLength $timeDir $treeHeight $zRef $sample2 stability[@] plotVeer $timeDir $treeHeight $zRef $sample1 stability[@] #------------------------------------------------------------------------------