-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
src/adjoint/boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
// ************************************************************************* // |
154 changes: 154 additions & 0 deletions
154
src/adjoint/boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.H
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
// ************************************************************************* // |