Skip to content

Commit

Permalink
Added a varying aoa bc.
Browse files Browse the repository at this point in the history
  • Loading branch information
friedenhe committed Nov 29, 2023
1 parent 7c5ebda commit e6ecf7d
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/adjoint/Make/files_Compressible
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ DASolver/DATurboFoam/DATurboFoam.C

boundaryConditions/multiFreqVector/multiFreqVectorFvPatchField.C
boundaryConditions/nutUSpaldingWallFunctionDF/nutUSpaldingWallFunctionFvPatchScalarFieldDF.C
boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.C
models/dummyTurbulenceModel/makeDummyTurbulenceModelCompressible.C
models/SpalartAllmarasFv3/makeSpalartAllmarasFv3Compressible.C
models/SpalartAllmarasFv3FieldInversion/makeSpalartAllmarasFv3FieldInversionCompressible.C
Expand Down
1 change: 1 addition & 0 deletions src/adjoint/Make/files_Incompressible
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ DASolver/DAPimpleDyMFoam/DAPimpleDyMFoam.C

boundaryConditions/multiFreqVector/multiFreqVectorFvPatchField.C
boundaryConditions/nutUSpaldingWallFunctionDF/nutUSpaldingWallFunctionFvPatchScalarFieldDF.C
boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.C
models/dummyTurbulenceModel/makeDummyTurbulenceModelIncompressible.C
models/SpalartAllmarasFv3/makeSpalartAllmarasFv3Incompressible.C
models/SpalartAllmarasFv3FieldInversion/makeSpalartAllmarasFv3FieldInversionIncompressible.C
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*---------------------------------------------------------------------------*\
DAFoam : Discrete Adjoint with OpenFOAM
Version : v3
This file is modified from OpenFOAM's source code
src/finiteVolume/fields/fvPatchFields/basic/fixedValue/fixedValueFvPatchField.C
OpenFOAM: The Open Source CFD Toolbox
Copyright (C): 2011-2016 OpenFOAM Foundation
OpenFOAM License:
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/

#include "varyingFlowDirectionFvPatchVectorField.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::varyingFlowDirectionFvPatchVectorField::varyingFlowDirectionFvPatchVectorField(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF)
: fixedValueFvPatchVectorField(p, iF),
UMag_(0.0),
flowDir_("x"),
normalDir_("y"),
alpha0_(0),
rate_(0)
{
}

Foam::varyingFlowDirectionFvPatchVectorField::varyingFlowDirectionFvPatchVectorField(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const dictionary& dict)
: fixedValueFvPatchVectorField(p, iF),
UMag_(dict.lookupOrDefault<scalar>("UMag", 0.0)),
flowDir_(dict.lookupOrDefault<word>("flowDir", "x")),
normalDir_(dict.lookupOrDefault<word>("normalDir", "y")),
alpha0_(dict.lookupOrDefault<scalar>("alpha0", 0.0)),
rate_(dict.lookupOrDefault<scalar>("rate", 0.0))
{

if (dict.found("value"))
{
fvPatchVectorField::operator=(
vectorField("value", dict, p.size()));
}
else
{
this->evaluate();
}
}

Foam::varyingFlowDirectionFvPatchVectorField::varyingFlowDirectionFvPatchVectorField(
const varyingFlowDirectionFvPatchVectorField& ptf,
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const fvPatchFieldMapper& mapper)
: fixedValueFvPatchVectorField(p, iF),
UMag_(ptf.UMag_),
flowDir_(ptf.flowDir_),
normalDir_(ptf.normalDir_),
alpha0_(ptf.alpha0_),
rate_(ptf.rate_)
{
this->evaluate();
}

Foam::varyingFlowDirectionFvPatchVectorField::varyingFlowDirectionFvPatchVectorField(
const varyingFlowDirectionFvPatchVectorField& wbppsf)
: fixedValueFvPatchVectorField(wbppsf),
UMag_(wbppsf.UMag_),
flowDir_(wbppsf.flowDir_),
normalDir_(wbppsf.normalDir_),
alpha0_(wbppsf.alpha0_),
rate_(wbppsf.rate_)
{
this->evaluate();
}

Foam::varyingFlowDirectionFvPatchVectorField::varyingFlowDirectionFvPatchVectorField(
const varyingFlowDirectionFvPatchVectorField& wbppsf,
const DimensionedField<vector, volMesh>& iF)
: fixedValueFvPatchVectorField(wbppsf, iF),
UMag_(wbppsf.UMag_),
flowDir_(wbppsf.flowDir_),
normalDir_(wbppsf.normalDir_),
alpha0_(wbppsf.alpha0_),
rate_(wbppsf.rate_)
{
this->evaluate();
}

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::varyingFlowDirectionFvPatchVectorField::updateCoeffs()
{
// calculate patch values
const scalar t = this->db().time().timeOutputValue();
scalar alpha = alpha0_ + t * rate_;

HashTable<label> compTable;
compTable.set("x", 0);
compTable.set("y", 1);
compTable.set("z", 2);

vectorField& thisPatchRef = *this;
vectorField thisPatch = thisPatchRef;
forAll(thisPatch, idxI)
{
label compFlow = compTable[flowDir_];
label compNormal = compTable[normalDir_];
thisPatch[idxI][compFlow] = UMag_ * cos(alpha);
thisPatch[idxI][compNormal] = UMag_ * sin(alpha);
}

fvPatchVectorField::operator==(thisPatch);

fixedValueFvPatchVectorField::updateCoeffs();
}

void Foam::varyingFlowDirectionFvPatchVectorField::write(Ostream& os) const
{
fixedValueFvPatchVectorField::write(os);
os.writeEntry("UMag", UMag_);
os.writeEntry("flowDir", flowDir_);
os.writeEntry("normalDir", normalDir_);
os.writeEntry("alpha0", alpha0_);
os.writeEntry("rate", rate_);
//writeEntry("value", os);
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
makePatchTypeField(
fvPatchVectorField,
varyingFlowDirectionFvPatchVectorField);
}

// ************************************************************************* //
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*---------------------------------------------------------------------------*\
DAFoam : Discrete Adjoint with OpenFOAM
Version : v3
This file is modified from OpenFOAM's source code
src/finiteVolume/fields/fvPatchFields/basic/fixedValue/fixedValueFvPatchField.H
OpenFOAM: The Open Source CFD Toolbox
Copyright (C): 2011-2016 OpenFOAM Foundation
OpenFOAM License:
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description:
This boundary condition provides a varying flow direction at the far field
U_flowDir = UMag * cos(alpha)
U_normalDir = UMag * sin(alpha)
alpha = alpha0 + rate * t
where
U_flowDir : velocity component parallel to the flow. Options are: x, y, or z
U_normalDir : velocity component normal to the flow. Options are: x, y, or z
UMag : velocity magnitude [m/s]
alpha0 : initial flow angle [rad]
rate : rate of change for the flow angle [rad/s]
Example of the boundary condition specification:
myPatch
{
type varyingFlowDirection;
UMag 10;
flowDir x;
normalDir y;
alpha0 0;
rate 0.1;
}
This will change the flow direction with a rate of 0.1 rad/s starting from 0 rad
U[0] = cos(0+0.1*t)
U[1] = sin(0+0.1*t)
\*---------------------------------------------------------------------------*/

#ifndef varyingFlowDirectionFvPatchVectorFields_H
#define varyingFlowDirectionFvPatchVectorFields_H

#include "fixedValueFvPatchFields.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
Class varyingFlowDirectionFvPatchVectorField Declaration
\*---------------------------------------------------------------------------*/

class varyingFlowDirectionFvPatchVectorField
: public fixedValueFvPatchVectorField
{
// Private data

scalar UMag_;
word flowDir_;
word normalDir_;
scalar alpha0_;
scalar rate_;

public:
//- Runtime type information
TypeName("varyingFlowDirection");

// Constructors

//- Construct from patch and internal field
varyingFlowDirectionFvPatchVectorField(
const fvPatch&,
const DimensionedField<vector, volMesh>&);

//- Construct from patch, internal field and dictionary
varyingFlowDirectionFvPatchVectorField(
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const dictionary&);

//- Construct by mapping given varyingFlowDirectionFvPatchVectorField onto
// a new patch
varyingFlowDirectionFvPatchVectorField(
const varyingFlowDirectionFvPatchVectorField&,
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const fvPatchFieldMapper&);

//- Construct as copy
varyingFlowDirectionFvPatchVectorField(
const varyingFlowDirectionFvPatchVectorField&);

//- Construct and return a clone
virtual tmp<fvPatchVectorField> clone() const
{
return tmp<fvPatchVectorField>(
new varyingFlowDirectionFvPatchVectorField(*this));
}

//- Construct as copy setting internal field reference
varyingFlowDirectionFvPatchVectorField(
const varyingFlowDirectionFvPatchVectorField&,
const DimensionedField<vector, volMesh>&);

//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchVectorField> clone(
const DimensionedField<vector, volMesh>& iF) const
{
return tmp<fvPatchVectorField>(
new varyingFlowDirectionFvPatchVectorField(*this, iF));
}

// Member functions

//- Update the patch field
virtual void updateCoeffs();

//- Write
virtual void write(Ostream&) const;
};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

0 comments on commit e6ecf7d

Please sign in to comment.