Commit f21279e6 authored by sgho's avatar sgho Committed by famen
Browse files

Clean up old Linux compilation routines;

Clean up compilation architecture (remove unused files and bring back flap_controller_cyclic);
Clean up CMakeLists.txt files
fixed the issue #10, #35 and #37
parent b0234aa5
Pipeline #16560 passed with stage
in 49 seconds
......@@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.0)
# Creating the project
project(DTUWEC LANGUAGES Fortran)
# message(${CMAKE_SOURCE_DIR})
# Set the source code directory
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(MODSRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/modules)
......@@ -10,6 +10,7 @@ set(IPCSRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/individual_pitch_controller)
set(DTUWEC_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/dtu_we_controller)
set(BLADED_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/dtu_we_controller_bladed)
set(FLAP_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/flap_controller_individual_aep_u_f)
set(FLAPCYC_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/flap_controller_cyclic)
set(BUILD_TYPE SHARED)
set(LIB static)
......@@ -26,9 +27,5 @@ add_subdirectory(${IPCSRC_DIR})
message("Configuring flap controller source files: " ${FLAP_SRC_DIR})
add_subdirectory(${FLAP_SRC_DIR})
# Adding all source files in ./source directory
# file(GLOB_RECURSE SRC *.f90)
# set(LIB_TYPE STATIC)
# include(${CMAKE_CURRENT_SOURCE_DIR}/utils/ci/CMakeListsFortranLibrary.txt)
message("Configuring cyclic flap controller source files: " ${FLAPCYC_SRC_DIR})
add_subdirectory(${FLAPCYC_SRC_DIR})
\ No newline at end of file
......@@ -4,13 +4,13 @@
## Introduction
The scope of this project is to provide an open-source open-access controller that can be used by the wind energy community as a reference. The DTU Wind Energy Controller (DTUWEC) is designed for pitch-regulated variable-speed wind turbines. It is built for high fidelity in-house aero-elastic simulation software (HAWC2). An interface to DNV-GL Bladed and OpenFAST is also provided for using DTUWEC with Bladed or OpenFAST. The controller features both partial and full load operation capabilities as well as switching mechanisms ensuring smooth transition between the two modes of operation. The partial load controller is based on a classical $`K\Omega^2`$ strategy or on a proportional-integral controller to track optimal tip speed ratio. The full load controller is also based on classical proportional-integral control theory. It also includes drivetrain and tower dampers, rotor speed exclusion zone control, de-rating control, wind speed estimation and filters on the feedback signal.
The DTUWEC also includes individual pitch control (IPC), individual flap control and cyclic flap control as separated DLLs.
The DTUWEC also includes individual pitch control (IPC), individual flap control and cyclic flap control as separated DLLs.
Blade pitch servo, generator models, flap servo, mechanical brake are not included in this repository. They can be found in the project [ServoAndUtilities](https://github.com/DTUWindEnergy/ServosAndUtilities).
## Compatibility
The project uses CMake to generate standard build files (e.g., makefiles on Linux/Mac OS and projects/solution files on Windows Visual studio) which could be used in the usual way.
The repository includes Visual Studio solution (for Windows) and CMakeLists.txt (for both Windows and Linux) to create DLLs to be used by HAWC2, Bladed and openFAST.
The controller is written in Fortran and it is compatible with Intel and GFortran compilers. It can be compiled both on Windows (32bit and 64bit) and Linux.
The controller is written in Fortran and it is compatible with Intel and GFortran compilers. It can be compiled both on Windows (32bit and 64bit) and Linux.
## Compilation
......@@ -33,10 +33,10 @@ The controller is written in Fortran and it is compatible with Intel and GFortra
```
>> cd build
```
- For 32-bit, in build folder run (make sure cmake command is inside your user environment PATH):
- For 32-bit, in build folder run (make sure cmake command is inside your user environment PATH):
```
>> cmake .. -G "Visual Studio 16 2019" -A Win32
>> cmake .. -G "Visual Studio 16 2019" -A Win32
```
- For 64-bit, in build folder run:
```
......@@ -44,7 +44,7 @@ The controller is written in Fortran and it is compatible with Intel and GFortra
```
- Now, a Visual Studio Solution file has been created and you could either use the following command to build the projects or open it with you Visual Studio IDE and build the projects as usual;
```
devenv DTUWEC.sln /Build
devenv DTUWEC.sln /Build
```
### Windows: CMake + GNU Fortran (gfortran)
......@@ -66,7 +66,7 @@ devenv DTUWEC.sln /Build
>> cmake .. -G "MinGW Makefiles" -D CMAKE_Fortran_COMPILER="gfortran" -D CMAKE_BUILD_TYPE="release"
>> mingw32-make
```
### Linux/Mac: CMake + GNU Fortran (gfortran) (WIP)
- Install CMake and gfortran (e.g. in Ubuntu). The minimum required CMake version is 3.12.4.
......@@ -90,3 +90,48 @@ $ cd build
$ cmake .. -DCMAKE_Fortran_COMPILER="gfortran"
$ make
```
### Linux on DTU's cluster Jess, to be used for MPI applications:
- In order to get access to all the submodules of the project, use the flag `--recurse-submodules` while cloning. To use the same user and password for all the git submodules, the git configuration can be also changed
before cloning:
```
$ git config --global credential.helper cache
$ git clone --recurse-submodules https://gitlab.windenergy.dtu.dk/OpenLAC/BasicDTUController.git
```
- Note that the default git version installed on 'Jess' does not support this capability, but it can be loaded
through the 'easy' module by typing the following sequence before cloning:
```
$ module purge
$ module load easy
$ ml git
$ unset SSH_ASKPASS
```
- Remember to re-type these lines before executing any git command, even after cloning.
- Note that switching to a new branch in the main BasicDTUController repository does not automatically update all the submodules included in this repository. In order to do so, please type:
```
$ git submodule update --init --recursive
```
- Load the compiler and a newer CMake version
```
$ module purge
$ module load easy
$ module load intel/2017a
$ module load CMake/3.15.3-GCCcore-7.3.0
```
- Create a "build" directory
```
$ mkdir build
```
- Going to your build directory
```
$ cd build
```
- In the build folder run the following command to build the makefile:
```
$ cmake .. -DCMAKE_Fortran_COMPILER=mpiifort
```
- In the build folder type make to build the code
```
$ make
```
import pytest
import sys
import os
import subprocess
"""
python ci.py <platform> [<configuration>] [push]
"""
if __name__ == '__main__':
module = 'DTU_Controller'
sln = 'src/dtu_controller.sln'
dll_lst = ['src/dtu_we_controller/%s/%s/dtu_we_controller%s.dll','src/dtu_we_controller_bladed/%s/%s/dtu_we_controller_bladed%s.dll']
binary_folder = 'control-%s'
def run(cmd):
print(cmd)
if os.system(cmd):
raise Exception("'%s' failed" % cmd)
def run_git_cmd(cmd):
git_repo_path = os.getcwd()
if not os.path.isdir(os.path.join(git_repo_path, ".git")):
raise Warning("'%s' does not appear to be a Git repository." % git_repo_path)
try:
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
cwd=os.path.abspath(git_repo_path))
stdout, stderr = process.communicate()
if process.returncode != 0:
raise EnvironmentError("%s\n%s" % (stdout, stderr))
return stdout.strip()
except EnvironmentError as e:
raise e
raise Warning("unable to run git")
platform = sys.argv[1]
if len(sys.argv) == 3 and sys.argv[2].lower() != 'push':
conf = sys.argv[2]
else:
conf = 'Release'
push = sys.argv[-1] == 'push'
ext = ['', '_64'][platform.lower() == 'x64']
binary_folder = binary_folder%platform
print("Run ci")
print("- Platform: %s" % platform)
print("- Solution file: %s" % (sln))
for dll in dll_lst:
print("- dll: " + dll % (platform, conf, ext))
print("-" * 20)
run('devenv %s /rebuild "%s|%s"' % (sln, conf, platform))
#res = pytest.main(['.'])
#if res:
# sys.exit(res)
run("git clone -b master --depth 1 git@gitlab.windenergy.dtu.dk:OpenLAC/control-binary/%s.git" % binary_folder)
tag = "%-12s"%run_git_cmd("git describe --tags")
message = run_git_cmd("git tag -n99 %s"%tag).replace(tag, "").strip()
date = run_git_cmd('git log -1 --format=%%ai --tags %s'%tag)[:10].strip()
name = run_git_cmd('git log -1 --format="%%an" --tags %s'%tag).strip()
with open('%s/changelog.txt'%binary_folder,'a') as fid:
info = " ".join([tag, date, name, module])
message = ("\n"+" "*60).join([l.strip() for l in message.split("\n")])
fid.write("%-60s%s\n"%(info[:58], message))
for dll in dll_lst:
run("%s %s/update_module.py %s" % (sys.executable, binary_folder, dll%(platform, conf, ext)))
if push:
run("%s %s/update_module.py push" % (sys.executable, binary_folder))
#define FILE_NAME "dtu_we_controller.dll"
#define FILE_DESCRIPTION "Basic DTU Controller"
FFLAGS=-fPIC -c -O3
LFLAGS=-shared -fPIC
%.o: %.f90
$(FC) $(FFLAGS) -I../dtu_we_controller $< -o $@
%.so: %.o
$(FC) $(LFLAGS) -I../dtu_we_controller $^ -o $@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2041
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "dtu_we_controller", "dtu_we_controller\dtu_we_controller.vfproj", "{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}"
EndProject
Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "dtu_we_controller_bladed", "dtu_we_controller_bladed\dtu_we_controller_bladed.vfproj", "{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}"
ProjectSection(ProjectDependencies) = postProject
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE} = {8DC2311E-C2DB-46DC-82FC-3671E2174EFE}
EndProjectSection
EndProject
Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "individual_pitch_controller", "individual_pitch_controller\individual_pitch_controller.vfproj", "{FC573039-61CB-45E3-B649-FC11C7AF5C2E}"
ProjectSection(ProjectDependencies) = postProject
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE} = {8DC2311E-C2DB-46DC-82FC-3671E2174EFE}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Debug|Win32.ActiveCfg = Debug|Win32
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Debug|Win32.Build.0 = Debug|Win32
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Debug|x64.ActiveCfg = Debug|x64
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Debug|x64.Build.0 = Debug|x64
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Release|Win32.ActiveCfg = Release|Win32
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Release|Win32.Build.0 = Release|Win32
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Release|x64.ActiveCfg = Release|x64
{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}.Release|x64.Build.0 = Release|x64
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Debug|Win32.ActiveCfg = Debug|Win32
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Debug|Win32.Build.0 = Debug|Win32
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Debug|x64.ActiveCfg = Debug|x64
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Debug|x64.Build.0 = Debug|x64
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Release|Win32.ActiveCfg = Release|Win32
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Release|Win32.Build.0 = Release|Win32
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Release|x64.ActiveCfg = Release|x64
{1C41A2C0-84C9-4DA1-A681-12B475CB23C9}.Release|x64.Build.0 = Release|x64
{FC573039-61CB-45E3-B649-FC11C7AF5C2E}.Debug|Win32.ActiveCfg = Debug|Win32
{FC573039-61CB-45E3-B649-FC11C7AF5C2E}.Debug|Win32.Build.0 = Debug|Win32
{FC573039-61CB-45E3-B649-FC11C7AF5C2E}.Debug|x64.ActiveCfg = Debug|Win32
{FC573039-61CB-45E3-B649-FC11C7AF5C2E}.Release|Win32.ActiveCfg = Release|Win32
{FC573039-61CB-45E3-B649-FC11C7AF5C2E}.Release|Win32.Build.0 = Release|Win32
{FC573039-61CB-45E3-B649-FC11C7AF5C2E}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5B7D83A7-40F0-46E7-B59C-7C541BE6AD61}
EndGlobalSection
EndGlobal
......@@ -7,10 +7,6 @@ message("Root Directory is: " ${ROOT_DIR})
# set source code
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(DTUWEC_SRC_DIR ${SRC_DIR})
# set(SRC ${DTUWEC_SRC_DIR}/dtu_we_controller_fcns.f90
# turbine_controller.f90
# safety_system.f90
# )
file(GLOB_RECURSE MODSRC "${ROOT_DIR}/src/modules/global_constants.f90"
"${ROOT_DIR}/src/modules/global_variables.f90"
"${ROOT_DIR}/src/modules/misc_mod.f90"
......@@ -23,19 +19,7 @@ file(GLOB_RECURSE SRC "${SRC_DIR}/dtu_we_controller.f90"
"${SRC_DIR}/safety_system.f90"
)
list (APPEND SRC ${MODSRC})
# add_library(turbine_controller_lib
# ${MODSRC}
# dtu_we_controller_fcns.f90
# turbine_controller.f90
# safety_system.f90
# )
# target_compile_options(turbine_controller_lib PRIVATE
# -cpp;
# -fcray-pointer;
# -ffree-form;
# -ffree-line-length-none;
# )
message("Including the utils: " "${ROOT_DIR}/utils/cmake/CMakeLists.txt")
include(${ROOT_DIR}/utils/cmake/CMakeLists.txt)
message("Including the utils: " "${ROOT_DIR}/utils/cmake/CMakeLists.txt")
# target_link_libraries(${PROJECT_NAME} turbine_controller_lib)
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject ProjectType="typeDynamicLibrary" ProjectCreator="Intel Fortran" Keyword="Dll" Version="11.0" ProjectIdGuid="{8DC2311E-C2DB-46DC-82FC-3671E2174EFE}">
<Platforms>
<Platform Name="Win32"/>
<Platform Name="x64"/></Platforms>
<Configurations>
<Configuration Name="Debug|Win32" OutputDirectory="$(PlatformName)\$(ConfigurationName)" IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" ConfigurationType="typeDynamicLibrary">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" WarnDeclarations="true" WarnUnusedVariables="true" WarnUncalled="true" WarnInterfaces="true" Traceback="true" BoundsCheck="true" RuntimeLibrary="rtMultiThreadedDebugDLL"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" GenerateDebugInformation="true" SubSystem="subSystemWindows" LinkDLL="true"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
<Tool Name="VFCustomBuildTool"/>
<Tool Name="VFPreLinkEventTool"/>
<Tool Name="VFPreBuildEventTool"/>
<Tool Name="VFPostBuildEventTool" CommandLine="del &quot;$(ProjectDir)$(OutDir)\version.res&quot;"/>
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
<Configuration Name="Release|Win32" OutputDirectory="$(PlatformName)\$(ConfigurationName)" IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" DeleteExtensionsOnClean="*.cod;*__genmod.*;*.obj;*.mod;*.pdb;*.asm;*.lst;*.map;*.dyn;*.dpi;*.tmp;*.log;*.ilk;*.exe;*.lib;$(TargetPath);*.htm" ConfigurationType="typeDynamicLibrary">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" WarnDeclarations="true" WarnUnusedVariables="true" WarnUncalled="true"/>
<Tool Name="VFLinkerTool" SuppressStartupBanner="true" ManifestFile="$(IntDir).intermediate.manifest" SubSystem="subSystemWindows" LinkDLL="true" AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
<Tool Name="VFCustomBuildTool"/>
<Tool Name="VFPreLinkEventTool"/>
<Tool Name="VFPreBuildEventTool" CommandLine="version.bat" Description="Extracting version info from git repository"/>
<Tool Name="VFPostBuildEventTool" CommandLine="del &quot;$(ProjectDir)$(OutDir)\version.res&quot;"/>
<Tool Name="VFManifestTool" SuppressStartupBanner="true" ResourceFile="$(IntDir).embed.manifest.res"/></Configuration>
<Configuration Name="Debug|x64" TargetName="$(ProjectName)_64" ConfigurationType="typeDynamicLibrary">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" WarnDeclarations="true" WarnUnusedVariables="true" WarnUncalled="true" WarnInterfaces="true" Traceback="true" BoundsCheck="true" RuntimeLibrary="rtMultiThreadedDebugDLL"/>
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" GenerateDebugInformation="true" SubSystem="subSystemWindows" LinkDLL="true"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true" TargetEnvironment="midlTargetAMD64"/>
<Tool Name="VFCustomBuildTool"/>
<Tool Name="VFPreLinkEventTool"/>
<Tool Name="VFPreBuildEventTool" CommandLine="version.bat"/>
<Tool Name="VFPostBuildEventTool" CommandLine="del &quot;$(ProjectDir)$(OutDir)\version.res&quot;"/>
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
<Configuration Name="Release|x64" TargetName="$(ProjectName)_64" DeleteExtensionsOnClean="*.cod;*__genmod.*;*.obj;*.mod;*.pdb;*.asm;*.lst;*.map;*.dyn;*.dpi;*.tmp;*.log;*.ilk;*.exe;*.lib;$(TargetPath);*.htm" ConfigurationType="typeDynamicLibrary">
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" WarnDeclarations="true" WarnUnusedVariables="true" WarnUncalled="true"/>
<Tool Name="VFLinkerTool" SuppressStartupBanner="true" ManifestFile="$(IntDir).intermediate.manifest" SubSystem="subSystemWindows" LinkDLL="true" AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"/>
<Tool Name="VFResourceCompilerTool"/>
<Tool Name="VFMidlTool" SuppressStartupBanner="true" TargetEnvironment="midlTargetAMD64"/>
<Tool Name="VFCustomBuildTool"/>
<Tool Name="VFPreLinkEventTool"/>
<Tool Name="VFPreBuildEventTool" CommandLine="version.bat" Description="Extracting version info from git repository"/>
<Tool Name="VFPostBuildEventTool" CommandLine="del &quot;$(ProjectDir)$(OutDir)\version.res&quot;"/>
<Tool Name="VFManifestTool" SuppressStartupBanner="true" ResourceFile="$(IntDir).embed.manifest.res"/></Configuration></Configurations>
<Files>
<Filter Name="Header Files" Filter="fi;fd"/>
<Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
<File RelativePath=".\version.rc"/></Filter>
<Filter Name="Source Files" Filter="f90;for;f;fpp;ftn;def;odl;idl">
<File RelativePath=".\BuildInfo.f90"/>
<File RelativePath=".\dtu_we_controller.f90"/>
<File RelativePath=".\dtu_we_controller_fcns.f90"/>
<File RelativePath=".\global_constants.f90"/>
<File RelativePath=".\global_variables.f90"/>
<File RelativePath=".\misc_mod.f90"/>
<File RelativePath=".\safety_system.f90"/>
<File RelativePath=".\turbine_controller.f90"/>
<File RelativePath=".\user_defined_types.f90"/>
<File RelativePath=".\write_version.f90"/></Filter></Files>
<Globals/></VisualStudioProject>
module global_constants
! Constants
integer, parameter :: mk = kind(1.0d0)
real(mk) pi, degrad, raddeg, rho
parameter(pi = 3.14159265358979_mk, degrad = 0.01745329251994_mk, raddeg = 57.295779513093144_mk, rho = 1.225_mk)
! More constant
integer MAXWPLINES, WORD_LENGTH, MAX_WORDS
integer MAX_NUM_Lambda, MAX_NUM_Pitch
parameter(MAXWPLINES=100)
parameter(MAX_NUM_Lambda=100)
parameter(MAX_NUM_Pitch=100)
parameter(WORD_LENGTH=256)
parameter(MAX_WORDS=50)
logical :: newtimestep=.TRUE.
end module global_constants
\ No newline at end of file
module global_variables
! This module contain the global variables that are used in this code
! Please declare all the global variables in this MODULE and USE it other files that you need the variable
!DEC$ IF .NOT. DEFINED(__LINUX__)
!DEC$ attributes DLLEXPORT :: pCtrlInputFile
!DEC$ END IF
use user_defined_types
implicit none
! Parameters
logical generator_cutin
integer PartialLoadControlMode, stoptype
integer CtrlStatus ! Integer indicating the status of the controller.
! (0: Normal operation, <0: Start-up, >0: Shutdown for different reasons)
real(mk) deltat
real(mk) RatedWindSpeed
real(mk) GenSpeedRefMax, GenSpeedRefMin, PeRated, GenTorqueRated, PitchStopAng, GenTorqueMax
real(mk) TTfa_PWR_lower, TTfa_PWR_upper, TorqueCtrlRatio
real(mk) Kopt, Kopt_dot, TSR_opt, R, GearRatio
real(mk) Vcutout, Vstorm
real(mk) Err0, ErrDot0, PitNonLin1, rel_limit
integer NAve_Pitch
real(mk) PitchAngles(1000,3),PitchRefs(1000,3)
real(mk) TAve_Pitch,DeltaPitchThreshold,AveragedMeanPitchAngles(3),AveragedPitchReference(3)
! Advanced controller input file
character(256) :: additionalCtrlParamFilename = ''
! Dynamic variables
integer :: stepno = 0, w_region = 0
real(mk) AddedPitchRate, PitchColRef0, GenTorqueRef0
real(mk) :: PitchColRef = 0.0_mk
real(mk) :: GenTorqueRef = 0.0_mk
real(mk) :: PitchColRefOld = 0.0_mk
real(mk) :: GenTorqueRefOld = 0.0_mk
real(mk) :: TimerGenCutin = 0.0_mk
real(mk) :: TimerStartup = 0.0_mk
real(mk) :: TimerExcl = 0.0_mk
real(mk) :: TimerShutdown = 0.0_mk
real(mk) :: TimerShutdown2 = 0.0_mk
real(mk) GenSpeed_at_stop, GenTorque_at_stop
real(mk) excl_flag
real(mk) :: outmax_old=0.0_mk,outmin_old=0.0_mk
logical :: fullload=.false.
integer :: CountPitchDeviation=0
real(mk) :: lambdaAtMinCt = 0.0_mk, pitchAtMinCt = 0.0_mk, minCt = 0.0_mk
real(mk) :: CpAtMinCt = 0.0_mk
!
! Variables with user defined Types
!
type(Tlowpass2order), save :: omega2ordervar
type(Tlowpass2order), save :: power2ordervar
type(Tfirstordervar), save :: pitchfirstordervar
type(Tfirstordervar), save :: wspfirstordervar
type(Tpidvar), save :: PID_gen_var
type(Tnotch2order), save :: DT_mode_filt
type(Tnotch2order), save :: DT_mode_filt_torque
type(Tnotch2order), save :: pwr_DT_mode_filt
type(Tpid2var), save :: PID_pit_var
type(Tdamper), save :: DT_damper
type(Tdamper), save :: TTfa_damper
type(Tfirstordervar), save :: TTfa_PWRfirstordervar
type(Tcutin), save :: CutinVar
type(Tcutout), save :: CutoutVar
type(Tswitch), save :: SwitchVar
type(TSafetySystem), save :: MoniVar
type(TPitchGSvar), save :: PitchGSVar
type(TDeratevar), save :: Deratevar
type(TWindEstvar), save :: WindEstvar
type(Twpdata), save :: OPdatavar
type(Texclzone), save :: ExcluZone
! defined global variables for down regulation control strategy
type(TdownRegulationData), save :: downRegulationData
type(TcontrolFile), save :: additionalCtrlParamFile
! define global avariables for windspeed estimator
type(TCpData), save :: CpData
type(TcontrolFile), pointer :: pCtrlInputFile
!**************************************************************************************************
end module global_variables
\ No newline at end of file
module misc_mod
!
! Module where IO and filter functions are defined.
! some parameters of the type defined filters have default values but not all
!
use user_defined_types
implicit none
integer, save :: ctrl_logfile_unit = 78
contains
!**************************************************************************************************
subroutine getFreeFileUnit(unitnr) bind(c, name='getFreeFileUnit')
integer,intent(inout) :: unitnr
integer, save :: lastUsedUnitNum = 127
unitnr=lastUsedUnitNum+1
lastUsedUnitNum=unitnr
end subroutine getFreeFileUnit
!**************************************************************************************************
subroutine GetFreeFileUnitDllCall(unitnr) bind(c, name='GetFreeFileUnitDllCall')
!DEC$ IF .NOT. DEFINED(__LINUX__)
!DEC$ ATTRIBUTES DLLEXPORT :: GetFreeFileUnitDllCall
!DEC$ END IF
integer,intent(inout) :: unitnr
integer, save :: lastUsedUnitNum = 127
unitnr=lastUsedUnitNum+1
lastUsedUnitNum=unitnr
end subroutine GetFreeFileUnitDllCall
!**************************************************************************************************
! Returns true if a file or folder exist
logical function fileExists(filename)
character(len=*),intent(in) :: filename !
INQUIRE(FILE=trim(filename), EXIST=fileExists) ! true if exist
end function fileExists
!**************************************************************************************************
! Returns true if a file or folder exist
logical function fileExistsDllCall(filename) bind(c, name='fileExistsDllCall')
!DEC$ IF .NOT. DEFINED(__LINUX__)
!DEC$ ATTRIBUTES DLLEXPORT :: fileExistsDllCall
!DEC$ END IF
character(len=*),intent(in) :: filename !
INQUIRE(FILE=trim(filename), EXIST=fileExistsDllCall) ! true if exist
end function fileExistsDllCall
!**************************************************************************************************
function lowpass1orderfilt(dt, stepno, filt, x)
! First order low-pass filter.
integer stepno
real(mk) lowpass1orderfilt, dt, x, y, a1, b1, b0, tau
type(Tfirstordervar) filt
! Step
if ((stepno .eq. 1) .and. (stepno .gt. filt%stepno1)) then
filt%x1_old = x
filt%y1_old = x
y=x
else
if (stepno .gt. filt%stepno1) then
filt%x1_old = filt%x1
filt%y1_old = filt%y1
endif
tau = filt%tau
a1 = (2.0_mk*tau - dt) / (2.0_mk*tau + dt)
b0 = dt / (2.0_mk*tau + dt)
b1 = b0
y = a1*filt%y1_old + b0*x + b1*filt%x1_old
endif
! Save previous values
filt%x1 = x
filt%y1 = y
filt%stepno1 = stepno
! Output
lowpass1orderfilt = y
return
end function lowpass1orderfilt
!**************************************************************************************************
function lowpass2orderfilt(dt, stepno, filt, x)
! Second order low-pass filter.
real(mk) lowpass2orderfilt(2), dt, x
integer stepno
type(Tlowpass2order) filt
! local vars
real(mk) y, f0, zeta, a1, a2, b0, b1, b2, denom
! Step
if ((stepno .eq. 1) .and. (stepno .gt. filt%stepno1)) then
filt%x1 = x
filt%x2 = x
filt%x1_old = filt%x1
filt%x2_old = filt%x2
filt%y1 = x
filt%y2 = x
filt%y1_old = filt%y1
filt%y2_old = filt%y2
y=x
else
if (stepno .gt. filt%stepno1) then
filt%x1_old = filt%x1
filt%x2_old = filt%x2
filt%y1_old = filt%y1
filt%y2_old = filt%y2
endif
f0 = filt%f0
zeta = filt%zeta
denom = 3.0_mk + 6.0_mk*zeta*pi*f0*dt + 4.0_mk*pi**2*f0**2*dt**2
a1 = (6.0_mk - 4.0_mk*pi**2*f0**2*dt**2)/denom
a2 = (-3.0_mk + 6.0_mk*zeta*pi*f0*dt - 4.0_mk*pi**2*f0**2*dt**2)/denom
b0 = 4.0_mk*pi**2*f0**2*dt**2/denom
b1 = b0
b2 = b0
y = a1*filt%y1_old + a2*filt%y2_old + b0*x + b1*filt%x1_old + b2*filt%x2_old
endif
! Save previous values
filt%x2 = filt%x1_old