|
| 1 | +/*---------------------------------------------------------------------------*\ |
| 2 | + ========= | |
| 3 | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| 4 | + \\ / O peration | |
| 5 | + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation |
| 6 | + \\/ M anipulation | |
| 7 | +------------------------------------------------------------------------------- |
| 8 | +License |
| 9 | + This file is part of OpenFOAM. |
| 10 | +
|
| 11 | + OpenFOAM is free software: you can redistribute it and/or modify it |
| 12 | + under the terms of the GNU General Public License as published by |
| 13 | + the Free Software Foundation, either version 3 of the License, or |
| 14 | + (at your option) any later version. |
| 15 | +
|
| 16 | + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT |
| 17 | + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 | + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 19 | + for more details. |
| 20 | +
|
| 21 | + You should have received a copy of the GNU General Public License |
| 22 | + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. |
| 23 | +
|
| 24 | +\*---------------------------------------------------------------------------*/ |
| 25 | + |
| 26 | +#include "customActuationDiskSource.H" |
| 27 | + |
| 28 | +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // |
| 29 | + |
| 30 | +namespace Foam |
| 31 | +{ |
| 32 | +namespace fv |
| 33 | +{ |
| 34 | + defineTypeNameAndDebug(customActuationDiskSource, 0); |
| 35 | + addToRunTimeSelectionTable |
| 36 | + ( |
| 37 | + option, |
| 38 | + customActuationDiskSource, |
| 39 | + dictionary |
| 40 | + ); |
| 41 | +} |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // |
| 46 | + |
| 47 | +void Foam::fv::customActuationDiskSource::checkData() const |
| 48 | +{ |
| 49 | + if (magSqr(this->diskArea()) <= VSMALL) |
| 50 | + { |
| 51 | + FatalErrorInFunction |
| 52 | + << "diskArea is approximately zero" |
| 53 | + << exit(FatalIOError); |
| 54 | + } |
| 55 | + if ((Cp_ <= VSMALL) || (Ct_ <= VSMALL)) |
| 56 | + { |
| 57 | + FatalErrorInFunction |
| 58 | + << "Cp and Ct must be greater than zero" |
| 59 | + << exit(FatalIOError); |
| 60 | + } |
| 61 | + if (mag(diskDir_) < VSMALL) |
| 62 | + { |
| 63 | + FatalErrorInFunction |
| 64 | + << "disk direction vector is approximately zero" |
| 65 | + << exit(FatalIOError); |
| 66 | + } |
| 67 | + if (returnReduce(upstreamCellId_, maxOp<label>()) == -1) |
| 68 | + { |
| 69 | + FatalErrorInFunction |
| 70 | + << "upstream location " << upstreamPoint_ << " not found in mesh" |
| 71 | + << exit(FatalIOError); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // |
| 76 | + |
| 77 | +Foam::fv::customActuationDiskSource::customActuationDiskSource |
| 78 | +( |
| 79 | + const word& name, // name as appears in fvOptions dictionary |
| 80 | + const word& modelType, // type of this instance |
| 81 | + const dictionary& dict, |
| 82 | + const fvMesh& mesh |
| 83 | +) |
| 84 | +: |
| 85 | + // call the base class constructor |
| 86 | + option(name, modelType, dict, mesh), |
| 87 | + // read control parameters from dictionary |
| 88 | + diskDir_(coeffs_.lookup("diskDir")), |
| 89 | + diskCentre_(coeffs_.lookup("diskCentre")), |
| 90 | + D_(readScalar(coeffs_.lookup("D"))), |
| 91 | + t_(readScalar(coeffs_.lookup("thickness"))), |
| 92 | + Cp_(readScalar(coeffs_.lookup("Cp"))), |
| 93 | + Ct_(readScalar(coeffs_.lookup("Ct"))), |
| 94 | + upstreamPoint_(coeffs_.lookup("upstreamPoint")), |
| 95 | + // initialise other member fields |
| 96 | + upstreamCellId_(-1), |
| 97 | + V_(0.0) |
| 98 | +{ |
| 99 | + Info << tab << "- creating actuation disk zone: " << this->name() << endl; |
| 100 | + |
| 101 | + // recover names of fields which are to be fed the sources into |
| 102 | + coeffs_.lookup("fields") >> fieldNames_; |
| 103 | + // prepare a list of boolean values for each field - used by the parent class |
| 104 | + // to determine whether the sources have been applied yet or not. |
| 105 | + applied_.setSize(fieldNames_.size(), false); |
| 106 | + |
| 107 | + // Locate the upstream cell used to apply velocity magnitude augment |
| 108 | + upstreamCellId_ = mesh.findCell(upstreamPoint_); |
| 109 | + |
| 110 | + // === |
| 111 | + // select cells forming part of the actuator disk |
| 112 | + |
| 113 | + // make sure direction vector is unit length |
| 114 | + diskDir_ /= mag(diskDir_); |
| 115 | + |
| 116 | + // Create a dimensioned origin position to use with default OF mesh types |
| 117 | + dimensionedVector x0 ("x0", dimLength, diskCentre_); |
| 118 | + |
| 119 | + // compute distance and normal vectors from origin of the disk to use for selection |
| 120 | + scalarField R (mag(mesh_.C() - x0)); |
| 121 | + vectorField rHat ((mesh_.C() - x0) / mag(mesh_.C() - x0)); |
| 122 | + |
| 123 | + // go over each cell in the grid and comapre it against selection criteria |
| 124 | + for (label cellI = 0; cellI < mesh_.C().size(); cellI++) |
| 125 | + { |
| 126 | + // determine distance from cell centre to disk axis and along the normal direction |
| 127 | + scalar dNormal = R[cellI] * (rHat[cellI] & diskDir_); |
| 128 | + scalar dRadial = sqrt(pow(R[cellI], 2.) - pow(dNormal, 2.)); |
| 129 | + |
| 130 | + // see if the cell is within tolerance from the centre of the disk |
| 131 | + if ((mag(dNormal) < t_/2.) && (dRadial < D_/2.)) |
| 132 | + cells_.append(cellI); |
| 133 | + } |
| 134 | + |
| 135 | + // === |
| 136 | + // Set volume information |
| 137 | + V_ = 0.0; |
| 138 | + forAll(cells_, i) |
| 139 | + V_ += mesh_.V()[cells_[i]]; |
| 140 | + reduce(V_, sumOp<scalar>()); |
| 141 | + |
| 142 | + // === |
| 143 | + // validate inputs |
| 144 | + checkData(); |
| 145 | + |
| 146 | + Info << tab |
| 147 | + << "- selected " << returnReduce(cells_.size(), sumOp<label>()) |
| 148 | + << " cell(s) with volume " << V_ << endl; |
| 149 | +} |
| 150 | + |
| 151 | +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // |
| 152 | + |
| 153 | +void Foam::fv::customActuationDiskSource::addSup |
| 154 | +( |
| 155 | + fvMatrix<vector>& eqn, |
| 156 | + const label fieldi |
| 157 | +) |
| 158 | +{ |
| 159 | + const scalarField& cellsV = mesh_.V(); |
| 160 | + vectorField& Usource = eqn.source(); |
| 161 | + const vectorField& U = eqn.psi(); |
| 162 | + |
| 163 | + if (V() > VSMALL) |
| 164 | + { |
| 165 | + calculateMomentumSource |
| 166 | + ( |
| 167 | + Usource, |
| 168 | + cells_, |
| 169 | + cellsV, |
| 170 | + geometricOneField(), |
| 171 | + U |
| 172 | + ); |
| 173 | + } |
| 174 | +} |
| 175 | + |
| 176 | +void Foam::fv::customActuationDiskSource::addSup |
| 177 | +( |
| 178 | + const volScalarField& rho, |
| 179 | + fvMatrix<vector>& eqn, |
| 180 | + const label fieldi |
| 181 | +) |
| 182 | +{ |
| 183 | + const scalarField& cellsV = mesh_.V(); |
| 184 | + vectorField& Usource = eqn.source(); |
| 185 | + const vectorField& U = eqn.psi(); |
| 186 | + |
| 187 | + if (V() > VSMALL) |
| 188 | + { |
| 189 | + calculateMomentumSource |
| 190 | + ( |
| 191 | + Usource, |
| 192 | + cells_, |
| 193 | + cellsV, |
| 194 | + rho, |
| 195 | + U |
| 196 | + ); |
| 197 | + } |
| 198 | +} |
| 199 | + |
| 200 | +bool Foam::fv::customActuationDiskSource::read(const dictionary& dict) |
| 201 | +{ |
| 202 | + if (option::read(dict)) |
| 203 | + { |
| 204 | + coeffs_.readIfPresent("diskDir", diskDir_); |
| 205 | + coeffs_.readIfPresent("diskCentre", diskCentre_); |
| 206 | + coeffs_.readIfPresent("D", D_); |
| 207 | + coeffs_.readIfPresent("thickness", t_); |
| 208 | + coeffs_.readIfPresent("Cp", Cp_); |
| 209 | + coeffs_.readIfPresent("Ct", Ct_); |
| 210 | + |
| 211 | + checkData(); |
| 212 | + |
| 213 | + return true; |
| 214 | + } |
| 215 | + else |
| 216 | + { |
| 217 | + return false; |
| 218 | + } |
| 219 | +} |
| 220 | + |
| 221 | +// ************************************************************************* // |
0 commit comments