From eb23bb0ef9e3f6519ccfa21390c5301feea24ab8 Mon Sep 17 00:00:00 2001 From: Ping He Date: Thu, 30 Nov 2023 18:36:52 -0600 Subject: [PATCH] Added a varying aoa bc. (#532) --- src/adjoint/Make/files_Compressible | 1 + src/adjoint/Make/files_Incompressible | 1 + .../varyingFlowDirectionFvPatchVectorField.C | 158 ++++++++++++++++++ .../varyingFlowDirectionFvPatchVectorField.H | 154 +++++++++++++++++ 4 files changed, 314 insertions(+) create mode 100755 src/adjoint/boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.C create mode 100755 src/adjoint/boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.H diff --git a/src/adjoint/Make/files_Compressible b/src/adjoint/Make/files_Compressible index d6865703..b57407b5 100755 --- a/src/adjoint/Make/files_Compressible +++ b/src/adjoint/Make/files_Compressible @@ -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 diff --git a/src/adjoint/Make/files_Incompressible b/src/adjoint/Make/files_Incompressible index a30733cc..03e6d78a 100755 --- a/src/adjoint/Make/files_Incompressible +++ b/src/adjoint/Make/files_Incompressible @@ -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 diff --git a/src/adjoint/boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.C b/src/adjoint/boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.C new file mode 100755 index 00000000..ed2ceb52 --- /dev/null +++ b/src/adjoint/boundaryConditions/varyingFlowDirection/varyingFlowDirectionFvPatchVectorField.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "varyingFlowDirectionFvPatchVectorField.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::varyingFlowDirectionFvPatchVectorField::varyingFlowDirectionFvPatchVectorField( + const fvPatch& p, + const DimensionedField& iF) + : fixedValueFvPatchVectorField(p, iF), + UMag_(0.0), + flowDir_("x"), + normalDir_("y"), + alpha0_(0), + rate_(0) +{ +} + +Foam::varyingFlowDirectionFvPatchVectorField::varyingFlowDirectionFvPatchVectorField( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict) + : fixedValueFvPatchVectorField(p, iF), + UMag_(dict.lookupOrDefault("UMag", 0.0)), + flowDir_(dict.lookupOrDefault("flowDir", "x")), + normalDir_(dict.lookupOrDefault("normalDir", "y")), + alpha0_(dict.lookupOrDefault("alpha0", 0.0)), + rate_(dict.lookupOrDefault("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& 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& 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