Skip to content

Commit b8b1b97

Browse files
authored
Added actuatorLine and actuatorPoint. (#769)
1 parent b859140 commit b8b1b97

File tree

9 files changed

+553
-76
lines changed

9 files changed

+553
-76
lines changed

src/adjoint/DAFvSource/DAFvSourceActuatorLine.C

Lines changed: 102 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ DAFvSourceActuatorLine::DAFvSourceActuatorLine(
2525
: DAFvSource(modelType, mesh, daOption, daModel, daIndex)
2626
{
2727
printIntervalUnsteady_ = daOption.getOption<label>("printIntervalUnsteady");
28+
this->initFvSourcePars();
2829
}
2930
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
3031

@@ -50,6 +51,10 @@ void DAFvSourceActuatorLine::calcFvSource(volVectorField& fvSource)
5051

5152
dictionary fvSourceSubDict = daOption_.getAllOptions().subDict("fvSource");
5253

54+
DAGlobalVar& globalVar =
55+
const_cast<DAGlobalVar&>(mesh_.thisDb().lookupObject<DAGlobalVar>("DAGlobalVar"));
56+
HashTable<List<scalar>>& actuatorLinePars = globalVar.actuatorLinePars;
57+
5358
// loop over all the cell indices for all actuator lines
5459
forAll(fvSourceSubDict.toc(), idxI)
5560
{
@@ -58,21 +63,22 @@ void DAFvSourceActuatorLine::calcFvSource(volVectorField& fvSource)
5863

5964
// sub dictionary with all parameters for this disk
6065
dictionary lineSubDict = fvSourceSubDict.subDict(lineName);
61-
62-
// now read in all parameters for this actuator line
6366
// center of the actuator line
64-
scalarList center1;
65-
lineSubDict.readEntry<scalarList>("center", center1);
66-
vector center = {center1[0], center1[1], center1[2]};
67+
vector center = {
68+
actuatorLinePars[lineName][0],
69+
actuatorLinePars[lineName][1],
70+
actuatorLinePars[lineName][2]};
6771
// thrust direction
68-
scalarList direction1;
69-
lineSubDict.readEntry<scalarList>("direction", direction1);
70-
vector direction = {direction1[0], direction1[1], direction1[2]};
72+
vector direction = {
73+
actuatorLinePars[lineName][3],
74+
actuatorLinePars[lineName][4],
75+
actuatorLinePars[lineName][5]};
7176
direction = direction / mag(direction);
7277
// initial vector for the actuator line
73-
scalarList initial1;
74-
lineSubDict.readEntry<scalarList>("initial", initial1);
75-
vector initial = {initial1[0], initial1[1], initial1[2]};
78+
vector initial = {
79+
actuatorLinePars[lineName][6],
80+
actuatorLinePars[lineName][7],
81+
actuatorLinePars[lineName][8]};
7682
initial = initial / mag(initial);
7783
if (fabs(direction & initial) > 1.0e-10)
7884
{
@@ -81,22 +87,22 @@ void DAFvSourceActuatorLine::calcFvSource(volVectorField& fvSource)
8187
// rotation direction, can be either right or left
8288
word rotDir = lineSubDict.getWord("rotDir");
8389
// inner and outer radius of the lines
84-
scalar innerRadius = lineSubDict.get<scalar>("innerRadius");
85-
scalar outerRadius = lineSubDict.get<scalar>("outerRadius");
90+
scalar innerRadius = actuatorLinePars[lineName][9];
91+
scalar outerRadius = actuatorLinePars[lineName][10];
8692
// rotation speed in rpm
87-
scalar rpm = lineSubDict.get<scalar>("rpm");
93+
scalar rpm = actuatorLinePars[lineName][15];
8894
scalar radPerS = rpm / 60.0 * 2.0 * pi;
8995
// smooth factor which should be of grid size
90-
scalar eps = lineSubDict.get<scalar>("eps");
96+
scalar eps = actuatorLinePars[lineName][17];
9197
// scaling factor to ensure a desired integrated thrust
92-
scalar scale = lineSubDict.get<scalar>("scale");
98+
scalar scale = actuatorLinePars[lineName][11];
9399
// phase (rad) of the rotation positive value means rotates ahead of time for phase rad
94-
scalar phase = lineSubDict.get<scalar>("phase");
100+
scalar phase = actuatorLinePars[lineName][16];
95101
// number of blades for this line model
96102
label nBlades = lineSubDict.get<label>("nBlades");
97-
scalar POD = lineSubDict.getScalar("POD");
98-
scalar expM = lineSubDict.getScalar("expM");
99-
scalar expN = lineSubDict.getScalar("expN");
103+
scalar POD = actuatorLinePars[lineName][12];
104+
scalar expM = actuatorLinePars[lineName][13];
105+
scalar expN = actuatorLinePars[lineName][14];
100106
// Now we need to compute normalized eps in the radial direction, i.e. epsRStar this is because
101107
// we need to smooth the radial distribution of the thrust, here the radial location is
102108
// normalized as rStar = (r - rInner) / (rOuter - rInner), so to make epsRStar consistent with this
@@ -157,24 +163,20 @@ void DAFvSourceActuatorLine::calcFvSource(volVectorField& fvSource)
157163
for (label bb = 0; bb < nBlades; bb++)
158164
{
159165
scalar thetaBlade = bb * 2.0 * pi / nBlades + radPerS * t + phase;
160-
if (daOption_.getOption<word>("runStatus") == "solvePrimal")
166+
#ifdef CODI_NO_AD
167+
if (cellI == 0)
161168
{
162-
if (cellI == 0)
169+
if (mesh_.time().timeIndex() % printIntervalUnsteady_ == 0
170+
|| mesh_.time().timeIndex() == 1)
163171
{
164-
if (mesh_.time().timeIndex() % printIntervalUnsteady_ == 0
165-
|| mesh_.time().timeIndex() == 1)
166-
{
167-
scalar twoPi = 2.0 * pi;
168-
Info << "blade " << bb << " theta: "
169-
#if defined(CODI_ADF) || defined(CODI_ADR)
170-
<< fmod(thetaBlade.getValue(), twoPi.getValue()) * 180.0 / pi.getValue()
171-
#else
172-
<< fmod(thetaBlade, twoPi) * 180.0 / pi
173-
#endif
174-
<< " deg" << endl;
175-
}
172+
scalar twoPi = 2.0 * pi;
173+
Info << "blade " << bb << " theta: "
174+
//<< fmod(thetaBlade.getValue(), twoPi.getValue()) * 180.0 / pi.getValue()
175+
<< fmod(thetaBlade, twoPi) * 180.0 / pi
176+
<< " deg" << endl;
176177
}
177178
}
179+
#endif
178180
// compute the rotated vector of initial by thetaBlade degree
179181
// We use a simplified version of Rodrigues rotation formulation
180182
vector rotatedVec = vector::zero;
@@ -236,20 +238,79 @@ void DAFvSourceActuatorLine::calcFvSource(volVectorField& fvSource)
236238
reduce(thrustTotal, sumOp<scalar>());
237239
reduce(torqueTotal, sumOp<scalar>());
238240

239-
if (daOption_.getOption<word>("runStatus") == "solvePrimal")
241+
#ifdef CODI_NO_AD
242+
if (mesh_.time().timeIndex() % printIntervalUnsteady_ == 0 || mesh_.time().timeIndex() == 1)
240243
{
241-
if (mesh_.time().timeIndex() % printIntervalUnsteady_ == 0 || mesh_.time().timeIndex() == 1)
242-
{
243-
Info << "Actuator line source: " << lineName << endl;
244-
Info << "Total thrust source: " << thrustTotal << endl;
245-
Info << "Total torque source: " << torqueTotal << endl;
246-
}
244+
Info << "Actuator line source: " << lineName << endl;
245+
Info << "Total thrust source: " << thrustTotal << endl;
246+
Info << "Total torque source: " << torqueTotal << endl;
247247
}
248+
#endif
248249
}
249250

250251
fvSource.correctBoundaryConditions();
251252
}
252253

254+
void DAFvSourceActuatorLine::initFvSourcePars()
255+
{
256+
/*
257+
Description:
258+
Initialize the values for all types of fvSource in DAGlobalVar, including
259+
actuatorDiskPars, heatSourcePars, etc
260+
*/
261+
262+
// now we need to initialize actuatorDiskPars
263+
dictionary fvSourceSubDict = daOption_.getAllOptions().subDict("fvSource");
264+
265+
forAll(fvSourceSubDict.toc(), idxI)
266+
{
267+
word diskName = fvSourceSubDict.toc()[idxI];
268+
// sub dictionary with all parameters for this disk
269+
dictionary lineSubDict = fvSourceSubDict.subDict(diskName);
270+
word type = lineSubDict.getWord("type");
271+
272+
if (type == "actuatorLine")
273+
{
274+
275+
// now read in all parameters for this actuator disk
276+
scalarList centerList;
277+
lineSubDict.readEntry<scalarList>("center", centerList);
278+
279+
scalarList dirList;
280+
lineSubDict.readEntry<scalarList>("direction", dirList);
281+
282+
scalarList initList;
283+
lineSubDict.readEntry<scalarList>("initial", initList);
284+
285+
// we have 18 design variables for each line
286+
scalarList dvList(18);
287+
dvList[0] = centerList[0];
288+
dvList[1] = centerList[1];
289+
dvList[2] = centerList[2];
290+
dvList[3] = dirList[0];
291+
dvList[4] = dirList[1];
292+
dvList[5] = dirList[2];
293+
dvList[6] = initList[0];
294+
dvList[7] = initList[1];
295+
dvList[8] = initList[2];
296+
dvList[9] = lineSubDict.getScalar("innerRadius");
297+
dvList[10] = lineSubDict.getScalar("outerRadius");
298+
dvList[11] = lineSubDict.getScalar("scale");
299+
dvList[12] = lineSubDict.getScalar("POD");
300+
dvList[13] = lineSubDict.getScalar("expM");
301+
dvList[14] = lineSubDict.getScalar("expN");
302+
dvList[15] = lineSubDict.getScalar("rpm");
303+
dvList[16] = lineSubDict.getScalar("phase");
304+
dvList[17] = lineSubDict.getScalar("eps");
305+
306+
// set actuatorDiskPars
307+
DAGlobalVar& globalVar =
308+
const_cast<DAGlobalVar&>(mesh_.thisDb().lookupObject<DAGlobalVar>("DAGlobalVar"));
309+
globalVar.actuatorLinePars.set(diskName, dvList);
310+
}
311+
}
312+
}
313+
253314
} // End namespace Foam
254315

255316
// ************************************************************************* //

src/adjoint/DAFvSource/DAFvSourceActuatorLine.H

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "DAFvSource.H"
1515
#include "addToRunTimeSelectionTable.H"
16+
#include "DAGlobalVar.H"
1617

1718
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1819

@@ -51,6 +52,9 @@ public:
5152

5253
/// compute the FvSource term
5354
virtual void calcFvSource(volVectorField& fvSource);
55+
56+
/// Initialize the values for all types of fvSource in DAGlobalVar, including actuatorDiskPars, heatSourcePars, etc
57+
virtual void initFvSourcePars();
5458
};
5559

5660
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

0 commit comments

Comments
 (0)