From 302ac385b73bbb0f46ebb654b3c5bf4188c49133 Mon Sep 17 00:00:00 2001 From: Uwe Fechner Date: Sat, 7 May 2022 18:01:05 +0200 Subject: [PATCH] Three functions of windfield translated --- Project.toml | 4 +++- src/AtmosphericModels.jl | 3 ++- src/windfield.jl | 33 +++++++++++++++++---------------- test/runtests.jl | 6 ++++++ 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Project.toml b/Project.toml index 8887c0a..df5bb3b 100644 --- a/Project.toml +++ b/Project.toml @@ -4,15 +4,17 @@ authors = ["Uwe Fechner and contributors"] version = "0.1.0" [deps] +HypergeometricFunctions = "34004b35-14d8-5ef3-9330-4cdb6864b03a" KiteUtils = "90980105-b163-44e5-ba9f-8b1c83bb0533" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" TestEnv = "1e6cf692-eddd-4d53-88a5-2d735e33781b" [compat] -julia = "1.6, 1.7, 1.8" KiteUtils = "^0.3.4" Parameters = "^0.12" TestEnv = "1" +HypergeometricFunctions = "0.3" +julia = "1.6, 1.7, 1.8" [extras] BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" diff --git a/src/AtmosphericModels.jl b/src/AtmosphericModels.jl index 17ab3d3..366ca67 100644 --- a/src/AtmosphericModels.jl +++ b/src/AtmosphericModels.jl @@ -1,6 +1,6 @@ module AtmosphericModels -using KiteUtils, Parameters +using KiteUtils, Parameters, HypergeometricFunctions export AtmosphericModel, ProfileLaw, EXP, LOG, EXPLOG, FAST_EXP, FAST_LOG, FAST_EXPLOG export clear, calc_rho, calc_wind_factor @@ -92,5 +92,6 @@ function calc_wind_factor(s::AM, height, ::Type{Val{6}}) evalpoly(1/height, (1.0, 1735.2333827029918, 279373.0012683715)) end +include("windfield.jl") end diff --git a/src/windfield.jl b/src/windfield.jl index 62677f2..e2ac1e0 100644 --- a/src/windfield.jl +++ b/src/windfield.jl @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ This module provides methods to create a turbulent wind field and to read the actual wind velocity vector as function of the 3d position @@ -14,23 +13,25 @@ The code is based on the following papers: Engineering Mechanics 13(4), pp. 269-282. """ -# def pfq(z): -# return np.real(hyp2f1(1./3., 17./6., 4./3., z)) +function pfq(z) + _₂F₁(1. /3 , 17. /6, 4. /3, z) +end -# def calcSigma1(v_wind_gnd): -# # TODO: What is the meaning of this value ??? -# v_height = calcWindHeight(v_wind_gnd, HUB_HEIGHT) -# sigma1 = I_REF * (0.75 * v_height + 5.6) -# return sigma1 +function calc_sigma1(am, v_wind_gnd) + v_height = v_wind_gnd * calc_wind_factor(am, am.set.avg_height, Val{Int(EXP)}) + am.set.i_ref * (0.75 * v_height + 5.6) +end -# def nextpow2(i): -# """ -# Find 2^n that is equal to or greater than i. -# """ -# n = 1 -# while n < i: -# n *= 2 -# return n +""" +Find 2^n that is equal to or greater than i. +""" +function nextpow2(i) + n = 1 + while n < i + n *= 2 + end + n +end # def calcFullName(v_wind_gnd, basename='windfield_4050_500', rel_sigma = 1.0): # path = HOME+'/00PythonSoftware/KiteSim/Environment/' diff --git a/test/runtests.jl b/test/runtests.jl index a59632d..d9521f5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,3 +39,9 @@ end clear(am) end +@testset "windfield" begin + @test AtmosphericModels.pfq(0.1) ≈ 1.079576584249971 + @test AtmosphericModels.calc_sigma1(am, 10.0) ≈ 2.181983002542761 + @test AtmosphericModels.nextpow2(10) == 16 +end +