From 0c1c075c5b163f470020ce9cb1cefe1e6e76d502 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 7 Feb 2019 14:08:03 +0000 Subject: [PATCH] ENH: uniformFixedValue: adapt point bc. See #1046. --- src/OpenFOAM/Make/files | 1 - src/fvMotionSolver/Make/files | 1 + .../uniformFixedValuePointPatchField.C | 97 +++++++++++++++---- .../uniformFixedValuePointPatchField.H | 30 +++++- .../uniformFixedValuePointPatchFields.C | 0 .../uniformFixedValuePointPatchFields.H | 0 .../PatchFunction1/PatchFunction1New.C | 3 +- 7 files changed, 110 insertions(+), 22 deletions(-) rename src/{OpenFOAM/fields => fvMotionSolver}/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C (62%) rename src/{OpenFOAM/fields => fvMotionSolver}/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.H (88%) rename src/{OpenFOAM/fields => fvMotionSolver}/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.C (100%) rename src/{OpenFOAM/fields => fvMotionSolver}/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.H (100%) diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 8bc7b414da..127e91e270 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -699,7 +699,6 @@ $(constraintPointPatchFields)/wedge/wedgePointPatchFields.C derivedPointPatchFields = $(pointPatchFields)/derived $(derivedPointPatchFields)/slip/slipPointPatchFields.C $(derivedPointPatchFields)/fixedNormalSlip/fixedNormalSlipPointPatchFields.C -$(derivedPointPatchFields)/uniformFixedValue/uniformFixedValuePointPatchFields.C $(derivedPointPatchFields)/timeVaryingUniformFixedValue/timeVaryingUniformFixedValuePointPatchFields.C $(derivedPointPatchFields)/codedFixedValue/codedFixedValuePointPatchFields.C diff --git a/src/fvMotionSolver/Make/files b/src/fvMotionSolver/Make/files index 3f43482922..f9ba08367c 100644 --- a/src/fvMotionSolver/Make/files +++ b/src/fvMotionSolver/Make/files @@ -37,6 +37,7 @@ $(derivedPoint)/oscillatingDisplacement/oscillatingDisplacementPointPatchVectorF $(derivedPoint)/angularOscillatingDisplacement/angularOscillatingDisplacementPointPatchVectorField.C $(derivedPoint)/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C $(derivedPoint)/surfaceDisplacement/surfaceDisplacementPointPatchVectorField.C +$(derivedPoint)/uniformFixedValue/uniformFixedValuePointPatchFields.C $(derivedPoint)/waveDisplacement/waveDisplacementPointPatchVectorField.C $(derivedPoint)/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchFields.C diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C b/src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C similarity index 62% rename from src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C rename to src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C index 28ce8e1c0f..3b51496edc 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C +++ b/src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -26,6 +26,27 @@ License \*---------------------------------------------------------------------------*/ #include "uniformFixedValuePointPatchField.H" +#include "SubField.H" +#include "polyPatch.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // + +template +const Foam::polyPatch& +Foam::uniformFixedValuePointPatchField::getPatch(const pointPatch& p) +{ + const polyMesh& mesh = p.boundaryMesh().mesh()(); + label patchi = mesh.boundaryMesh().findPatchID(p.name()); + + if (patchi == -1) + { + FatalErrorInFunction + << "Cannot use uniformFixedValue on patch " << p.name() + << " since there is no underlying mesh patch" << exit(FatalError); + } + return mesh.boundaryMesh()[patchi]; +} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // @@ -52,7 +73,16 @@ uniformFixedValuePointPatchField ) : fixedValuePointPatchField(p, iF, dict, false), - uniformValue_(Function1::New("uniformValue", dict)) + uniformValue_ + ( + PatchFunction1::New + ( + this->getPatch(p), + "uniformValue", + dict, + false // generate point values + ) + ) { if (dict.found("value")) { @@ -63,8 +93,7 @@ uniformFixedValuePointPatchField } else { - const scalar t = this->db().time().timeOutputValue(); - fixedValuePointPatchField::operator=(uniformValue_->value(t)); + this->evaluate(); } } @@ -80,11 +109,18 @@ uniformFixedValuePointPatchField ) : fixedValuePointPatchField(ptf, p, iF, mapper), - uniformValue_(ptf.uniformValue_.clone()) + uniformValue_(ptf.uniformValue_.clone(this->getPatch(p))) { - // For safety re-evaluate - const scalar t = this->db().time().timeOutputValue(); - fixedValuePointPatchField::operator=(uniformValue_->value(t)); + if (mapper.direct() && !mapper.hasUnmapped()) + { + // Use mapping instead of re-evaluation + this->map(ptf, mapper); + } + else + { + // Evaluate since value not mapped + this->evaluate(); + } } @@ -96,7 +132,7 @@ uniformFixedValuePointPatchField ) : fixedValuePointPatchField(ptf), - uniformValue_(ptf.uniformValue_.clone()) + uniformValue_(ptf.uniformValue_.clone(this->getPatch(this->patch()))) {} @@ -109,16 +145,45 @@ uniformFixedValuePointPatchField ) : fixedValuePointPatchField(ptf, iF), - uniformValue_(ptf.uniformValue_.clone()) -{ - // For safety re-evaluate - const scalar t = this->db().time().timeOutputValue(); - fixedValuePointPatchField::operator==(uniformValue_->value(t)); -} + uniformValue_(ptf.uniformValue_.clone(this->getPatch(this->patch()))) +{} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::uniformFixedValuePointPatchField::autoMap +( + const pointPatchFieldMapper& mapper +) +{ + fixedValuePointPatchField::autoMap(mapper); + uniformValue_().autoMap(mapper); + + if (uniformValue_().constant()) + { + // If mapper is not dependent on time we're ok to evaluate + this->evaluate(); + } +} + + +template +void Foam::uniformFixedValuePointPatchField::rmap +( + const pointPatchField& ptf, + const labelList& addr +) +{ + fixedValuePointPatchField::rmap(ptf, addr); + + const uniformFixedValuePointPatchField& tiptf = + refCast(ptf); + + uniformValue_().rmap(tiptf.uniformValue_(), addr); +} + + template void Foam::uniformFixedValuePointPatchField::updateCoeffs() { @@ -126,10 +191,8 @@ void Foam::uniformFixedValuePointPatchField::updateCoeffs() { return; } - const scalar t = this->db().time().timeOutputValue(); fixedValuePointPatchField::operator==(uniformValue_->value(t)); - fixedValuePointPatchField::updateCoeffs(); } diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.H b/src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.H similarity index 88% rename from src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.H rename to src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.H index 3ede9eba71..31bc640cb6 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.H +++ b/src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -51,13 +51,15 @@ SourceFiles #define uniformFixedValuePointPatchField_H #include "fixedValuePointPatchField.H" -#include "Function1.H" +#include "PatchFunction1.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +class polyPatch; + /*---------------------------------------------------------------------------*\ Class uniformFixedValuePointPatchField Declaration \*---------------------------------------------------------------------------*/ @@ -67,9 +69,14 @@ class uniformFixedValuePointPatchField : public fixedValuePointPatchField { + // Private Member Functions + + static const polyPatch& getPatch(const pointPatch&); + + // Private data - autoPtr> uniformValue_; + autoPtr> uniformValue_; public: @@ -157,6 +164,23 @@ public: return uniformValue_; } + + // Mapping functions + + //- Map (and resize as needed) from self given a mapping object + virtual void autoMap + ( + const pointPatchFieldMapper& + ); + + //- Reverse map the given fvPatchField onto this fvPatchField + virtual void rmap + ( + const pointPatchField&, + const labelList& + ); + + // Evaluation functions //- Update the coefficients associated with the patch field diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.C b/src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.C similarity index 100% rename from src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.C rename to src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.C diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.H b/src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.H similarity index 100% rename from src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.H rename to src/fvMotionSolver/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchFields.H diff --git a/src/meshTools/PatchFunction1/PatchFunction1New.C b/src/meshTools/PatchFunction1/PatchFunction1New.C index 1b825980bc..d75d23c4f1 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1New.C +++ b/src/meshTools/PatchFunction1/PatchFunction1New.C @@ -102,7 +102,8 @@ Foam::autoPtr> Foam::PatchFunction1::New pp, PatchFunction1Types::ConstantField::typeName, entryName, - dict + dict, + faceValues ) ); }