VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
ActuatorFarm.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
32#ifndef ActuatorFarm_H
33#define ActuatorFarm_H
34
35#include "Parameter/Parameter.h"
37#include "logger/Logger.h"
38#include <basics/DataTypes.h>
40#include <cstddef>
41#include <optional>
42#include <string>
43#include <stdexcept>
44#include <vector>
45
46namespace vf::gpu {
47
48class GridProvider;
49
51{
52public:
74
78 const real diameter,
79 const std::vector<real>& bladeRadii,
80 const std::vector<real>& turbinePositionsX,
81 const std::vector<real>& turbinePositionsY,
82 const std::vector<real>& turbinePositionsZ,
83 const real smearingWidth,
84 const int level,
85 const bool useHostArrays,
86 const uint numberOfBlades = 3,
87 const std::optional<HubConfig>& hubConfig = std::nullopt,
88 const std::optional<TowerConfig>& towerConfig = std::nullopt,
89 const std::optional<VAWTConfig>& vawtConfig = std::nullopt,
90 const std::optional<FloatingConfig>& floatingConfig = std::nullopt
91 ) :
102 level(level),
104 hubLength(hubConfig ? hubConfig->length : 0.0),
105 hubRadius(hubConfig ? hubConfig->radius : 0.0),
106 hubPositionOffset(hubConfig ? hubConfig->positionOffset : 0.0),
107 numberOfHubPointsPerTurbine(hubConfig ? hubConfig->numberOfPointsPerTurbine : 0),
109 towerRadius(towerConfig ? towerConfig->radius : 0.0),
110 towerOffset(towerConfig ? towerConfig->offset : 0.0),
111 numberOfTowerPointsPerTurbine(towerConfig ? towerConfig->numberOfPointsPerTurbine : 0),
115 vawtRotorHeight(vawtConfig ? vawtConfig->rotorHeight : 0.0),
117 floatingMaximumAmplitudeX(floatingConfig ? floatingConfig->maximumAmplitudeX : 0.0),
118 floatingMaximumAmplitudeY(floatingConfig ? floatingConfig->maximumAmplitudeY : 0.0),
119 floatingMaximumAmplitudeZ(floatingConfig ? floatingConfig->maximumAmplitudeZ : 0.0),
120 maxFloatingAmplitude(std::hypot(floatingConfig ? floatingConfig->maximumAmplitudeX : 0.0,
121 floatingConfig ? floatingConfig->maximumAmplitudeY : 0.0,
122 floatingConfig ? floatingConfig->maximumAmplitudeZ : 0.0)),
124 {
125 using namespace vf::basics::constant;
126 const real deltaX = this->para->getScaledLengthRatio(level);
127 const real smearingWidthOverDx = this->smearingWidth / deltaX;
128 if(smearingWidthOverDx < c1o1)
129 throw std::runtime_error("ActuatorFarm::ActuatorFarm: smearing width needs to be larger than dx!");
131 throw std::runtime_error("ActuatorFarm::ActuatorFarm: turbine positions need to have the same length!");
132 if(numberOfBlades == 0)
133 throw std::runtime_error("ActuatorFarm::ActuatorFarm: number of blades must be larger than zero!");
135 throw std::runtime_error("ActuatorFarm::ActuatorFarm: tower heights vector size (" + std::to_string(towerHeights.size())
136 + ") must match number of turbines (" + std::to_string(numberOfTurbines) + ")!");
137 if (this->vawtRotorHeight < c0o1)
138 throw std::runtime_error("ActuatorFarm::ActuatorFarm: VAWT vawtRotorHeight must be non-negative!");
139
140 azimuths = std::vector<real>(numberOfTurbines, c0o1);
141 VF_LOG_INFO("ActuatorFarm parameters:");
142 VF_LOG_INFO("--------------");
143 VF_LOG_INFO("level = {}", this->level);
144 VF_LOG_INFO("number of turbines = {}", this->numberOfTurbines );
145 VF_LOG_INFO("number of blades = {}", this->numberOfBlades );
146 VF_LOG_INFO("points per blade: = {}", this->numberOfPointsPerBlade);
147 VF_LOG_INFO("rotor diameter [m] = {}", this->diameter);
148 VF_LOG_INFO("nodes per diameter = {}", this->diameter / deltaX);
149 VF_LOG_INFO("points per hub: = {}", this->numberOfHubPointsPerTurbine);
150 VF_LOG_INFO("points per tower: = {}", this->numberOfTowerPointsPerTurbine);
151 VF_LOG_INFO("smearing width [m] = {} ", this->smearingWidth);
152 VF_LOG_INFO("smearing width / dx = {} ",this->smearingWidth/deltaX);
153 if (this->hasVAWTRotorVolume()) {
154 VF_LOG_INFO("VAWT rotor vawtRotorHeight [m] = {}", this->vawtRotorHeight);
155 VF_LOG_INFO("VAWT flagLocalSmearingWidth = {}", this->flagLocalSmearingWidth);
156 }
157 }
158
159 ~ActuatorFarm() override;
160 void init() override;
161 void interact(int level, uint t) override;
163
164 void enableOutput(const std::string& outputName, uint tStart, uint tOut) {
165 this->outputName = outputName;
166 this->writeOutput = true;
167 this->tStartOut = tStart;
168 this->tOut = tOut;
169 }
170
171 void write(const std::string& filename) const;
172
173 uint getNumberOfTurbines() const { return this->numberOfTurbines; };
177
178 uint getNumberOfIndices() const { return this->numberOfIndices; };
182 uint getNumberOfHubPoints() const { return this->numberOfHubPoints; };
184
188 bool hasVAWTRotorVolume() const { return this->vawtRotorHeight > 0.0; }
190 real getVAWTRotorHeight() const { return this->vawtRotorHeight; }
192
193 real* getAllTurbinePosX() const { return turbinePosXH; };
194 real* getAllTurbinePosY() const { return turbinePosYH; };
195 real* getAllTurbinePosZ() const { return turbinePosZH; };
196
197 real getTurbinePosX(size_t turbine) const { return turbinePosXH[turbine]; };
198 real getTurbinePosY(size_t turbine) const { return turbinePosYH[turbine]; };
199 real getTurbinePosZ(size_t turbine) const { return turbinePosZH[turbine]; };
200
201 real* getAllBladeCoordsX() const { return this->coordsXH; };
202 real* getAllBladeCoordsY() const { return this->coordsYH; };
203 real* getAllBladeCoordsZ() const { return this->coordsZH; };
204 real* getAllBladeVelocitiesX() const { return this->velocitiesXH; };
205 real* getAllBladeVelocitiesY() const { return this->velocitiesYH; };
206 real* getAllBladeVelocitiesZ() const { return this->velocitiesZH; };
207 real* getAllBladeForcesX() const { return this->forcesXH; };
208 real* getAllBladeForcesY() const { return this->forcesYH; };
209 real* getAllBladeForcesZ() const { return this->forcesZH; };
211
212 real* getAllHubCoordsX() const { return numberOfHubPoints > 0 ? &this->coordsXH[this->numberOfBladePoints] : nullptr; };
213 real* getAllHubCoordsY() const { return numberOfHubPoints > 0 ? &this->coordsYH[this->numberOfBladePoints] : nullptr; };
214 real* getAllHubCoordsZ() const { return numberOfHubPoints > 0 ? &this->coordsZH[this->numberOfBladePoints] : nullptr; };
215 real* getAllHubVelocitiesX() const { return numberOfHubPoints > 0 ? &this->velocitiesXH[this->numberOfBladePoints] : nullptr; };
216 real* getAllHubVelocitiesY() const { return numberOfHubPoints > 0 ? &this->velocitiesYH[this->numberOfBladePoints] : nullptr; };
217 real* getAllHubVelocitiesZ() const { return numberOfHubPoints > 0 ? &this->velocitiesZH[this->numberOfBladePoints] : nullptr; };
218 real* getAllHubForcesX() const { return numberOfHubPoints > 0 ? &this->forcesXH[this->numberOfBladePoints] : nullptr; };
219 real* getAllHubForcesY() const { return numberOfHubPoints > 0 ? &this->forcesYH[this->numberOfBladePoints] : nullptr; };
220 real* getAllHubForcesZ() const { return numberOfHubPoints > 0 ? &this->forcesZH[this->numberOfBladePoints] : nullptr; };
221
222 real* getAllTowerCoordsX() const { return numberOfTowerPoints > 0 ? &this->coordsXH[this->numberOfBladePoints+this->numberOfHubPoints] : nullptr; };
223 real* getAllTowerCoordsY() const { return numberOfTowerPoints > 0 ? &this->coordsYH[this->numberOfBladePoints+this->numberOfHubPoints] : nullptr; };
224 real* getAllTowerCoordsZ() const { return numberOfTowerPoints > 0 ? &this->coordsZH[this->numberOfBladePoints+this->numberOfHubPoints] : nullptr; };
228 real* getAllTowerForcesX() const { return numberOfTowerPoints > 0 ? &this->forcesXH[this->numberOfBladePoints+this->numberOfHubPoints] : nullptr; };
229 real* getAllTowerForcesY() const { return numberOfTowerPoints > 0 ? &this->forcesYH[this->numberOfBladePoints+this->numberOfHubPoints] : nullptr; };
230 real* getAllTowerForcesZ() const { return numberOfTowerPoints > 0 ? &this->forcesZH[this->numberOfBladePoints+this->numberOfHubPoints] : nullptr; };
231
241
252
253
263
273
277
278 void setTurbineBladeCoords(size_t turbine, const real* bladeCoordsX, const real* bladeCoordsY, const real* bladeCoordsZ) const;
280 void setTurbineBladeForces(size_t turbine, const real* bladeForcesX, const real* bladeForcesY, const real* bladeForcesZ) const;
281
282 void setTurbineAzimuth(size_t turbine, real azimuth){azimuths[turbine] = azimuth;}
283
284 virtual void updateForcesAndCoordinates(real time, real deltaT)=0;
285 virtual void appendOutputData(std::vector<std::string>&,
286 std::vector<std::vector<double>>&) const {};
287
288private:
289 void initTurbineGeometries();
290 void initBoundingVolumes();
291 void initCoords();
292 void initVelocities();
293 void initForces();
294 void initIndices();
295 std::string getFilename(uint t) const;
296 void swapDeviceArrays();
297 void generateHubAxisPoints(uint turbineIndex, uint& pointIndex);
298 void generateTowerAxisPoints(uint turbineIndex, uint& pointIndex);
299public:
305
308
317
320
321protected:
323 {
324 return (this->useLocalSmearingWidth() && this->vawtBoundingSmearingWidth > 0.0)
326 : this->smearingWidth;
327 }
329 {
330 using namespace vf::basics::constant;
331 return this->useLocalSmearingWidth()
332 ? c3o1 * this->getRotorBoundingSmearingWidth()
333 : c3o1 * this->smearingWidth;
334 }
336 {
337 return this->hasVAWTRotorVolume() && this->flagLocalSmearingWidth;
338 }
339
341 std::vector<real> azimuths;
343 const bool useHostArrays;
345 const real smearingWidth; // in m
346 const int level;
358 const std::vector<real> towerHeights;
365
366 bool writeOutput{false};
367 std::string outputName;
370};
371
372}
373
374#endif
375
#define VF_LOG_INFO(...)
Definition Logger.h:50
std::vector< real > initialTurbinePositionsZ
real * getAllVelocitiesXDevice() const
real * getAllHubForcesZ() const
real * getAllTowerForcesXDevice() const
const uint numberOfBladePoints
real * getAllTowerCoordsYDevice() const
real * getAllBladeVelocitiesY() const
real * getAllBladeVelocitiesZ() const
uint getNumberOfBladesPerTurbine() const
const real hubPositionOffset
real * getAllBladeLocalSmearingWidth() const
real * getAllForcesYDevice() const
real * getAllHubCoordsYDevice() const
real * getAllTowerCoordsZDevice() const
void setTurbineAzimuth(size_t turbine, real azimuth)
real * getAllTowerCoordsX() const
bool getFlagLocalSmearingWidth() const
void setTurbineBladeForces(size_t turbine, const real *bladeForcesX, const real *bladeForcesY, const real *bladeForcesZ) const
real * getAllForcesZDevice() const
const bool flagLocalSmearingWidth
uint getNumberOfBladePoints() const
const uint numberOfTowerPointsPerTurbine
const uint numberOfTowerPoints
real * getAllHubVelocitiesXDevice() const
const uint numberOfHubPoints
const real floatingMaximumAmplitudeX
real * getAllBladeCoordsXDevice() const
uint getNumberOfHubPoints() const
real * getAllBladeForcesY() const
~ActuatorFarm() override
real * localSmearingWidthDPreviousTimestep
void setAllBladeCoords(const real *bladeCoordsX, const real *bladeCoordsY, const real *bladeCoordsZ) const
real * getAllCoordsZDevice() const
real * getAllHubCoordsX() const
real * getAllBladeCoordsX() const
real * getAllBladeVelocitiesXDevice() const
real * getAllTowerForcesZDevice() const
void setAllBladeForces(const real *bladeForcesX, const real *bladeForcesY, const real *bladeForcesZ) const
real * getAllForcesXDevice() const
real * getAllHubForcesXDevice() const
real * getAllTurbinePosZ() const
uint getNumberOfBladePointsPerTurbine() const
const uint numberOfHubPointsPerTurbine
real * velocitiesXDPreviousTimestep
uint getNumberOfPointsPerBlade() const
const uint numberOfBladePointsPerTurbine
uint getNumberOfHubPointsPerTurbine() const
real * getAllBladeForcesYDevice() const
ActuatorFarm(SPtr< Parameter > para, SPtr< CudaMemoryManager > cudaMemoryManager, const real diameter, const std::vector< real > &bladeRadii, const std::vector< real > &turbinePositionsX, const std::vector< real > &turbinePositionsY, const std::vector< real > &turbinePositionsZ, const real smearingWidth, const int level, const bool useHostArrays, const uint numberOfBlades=3, const std::optional< HubConfig > &hubConfig=std::nullopt, const std::optional< TowerConfig > &towerConfig=std::nullopt, const std::optional< VAWTConfig > &vawtConfig=std::nullopt, const std::optional< FloatingConfig > &floatingConfig=std::nullopt)
real * getAllTowerCoordsY() const
real getTurbinePosZ(size_t turbine) const
real * getAllTowerCoordsZ() const
uint getNumberOfTurbines() const
real * velocitiesYDPreviousTimestep
real * localSmearingWidthDCurrentTimestep
real * getAllHubVelocitiesX() const
real * getAllHubCoordsY() const
bool useLocalSmearingWidth() const
std::vector< real > initialTurbinePositionsX
bool requiresLocalSmearingWidth() const
real * getAllBladeForcesZDevice() const
real * getAllTowerVelocitiesXDevice() const
std::vector< real > azimuths
real * getAllTowerVelocitiesX() const
real * getAllTowerVelocitiesZ() const
virtual void appendOutputData(std::vector< std::string > &, std::vector< std::vector< double > > &) const
real * getAllBladeVelocitiesX() const
real * getAllBladeVelocitiesYDevice() const
real * getAllTurbinePosY() const
real * getAllBladeForcesX() const
void setAllBladeVelocities(const real *bladeVelocitiesX, const real *bladeVelocitiesY, const real *bladeVelocitiesZ) const
const real floatingMaximumAmplitudeY
real * getAllTowerVelocitiesYDevice() const
real * getAllHubCoordsZDevice() const
real * getAllTurbinePosX() const
void getTaggedFluidNodes(GridProvider *gridProvider) override
real * getAllCoordsXDevice() const
real * getAllTowerVelocitiesZDevice() const
real getTurbinePosY(size_t turbine) const
real * getAllBladeVelocitiesZDevice() const
real * getAllHubForcesYDevice() const
real * getAllBladeForcesZ() const
real * getAllBladeCoordsYDevice() const
real getRotorBoundingSmearingWidth() const
real * getAllBladeCoordsY() const
uint getNumberOfTowerPoints() const
void init() override
uint getNumberOfTowerPointsPerTurbine() const
real getTurbinePosX(size_t turbine) const
real * getAllHubVelocitiesZ() const
real * getAllHubVelocitiesY() const
const real maxFloatingAmplitude
real * getAllHubCoordsZ() const
real getVAWTRotorHeight() const
void setTurbineBladeCoords(size_t turbine, const real *bladeCoordsX, const real *bladeCoordsY, const real *bladeCoordsZ) const
real * getAllTowerCoordsXDevice() const
void enableOutput(const std::string &outputName, uint tStart, uint tOut)
real * getAllVelocitiesZDevice() const
real * getAllTowerVelocitiesY() const
real getVAWTRotorBoundingMargin() const
real * getAllBladeLocalSmearingWidthDevice() const
virtual void updateForcesAndCoordinates(real time, real deltaT)=0
const uint numberOfPointsPerBlade
void setTurbineBladeVelocities(size_t turbine, const real *bladeVelocitiesX, const real *bladeVelocitiesY, const real *bladeVelocitiesZ) const
real * velocitiesZDPreviousTimestep
real * getAllHubVelocitiesYDevice() const
uint getTotalNumberOfPoints() const
real * getAllHubCoordsXDevice() const
real * getAllTowerForcesY() const
std::vector< real > bladeRadii
real * getAllHubForcesY() const
real * getAllHubForcesX() const
real * getAllTowerForcesZ() const
real * getAllCoordsYDevice() const
std::vector< real > initialTurbinePositionsY
uint getNumberOfIndices() const
const std::vector< real > towerHeights
void interact(int level, uint t) override
void write(const std::string &filename) const
real * getAllHubForcesZDevice() const
real * getAllTowerForcesX() const
real * getAllBladeCoordsZDevice() const
const uint numberOfTurbines
const real floatingMaximumAmplitudeZ
real * getAllHubVelocitiesZDevice() const
real * getAllBladeForcesXDevice() const
real * getAllTowerForcesYDevice() const
bool hasVAWTRotorVolume() const
real * getAllBladeCoordsZ() const
real * getAllVelocitiesYDevice() const
SPtr< CudaMemoryManager > cudaMemoryManager
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47