From 0c1c075c5b163f470020ce9cb1cefe1e6e76d502 Mon Sep 17 00:00:00 2001 From: mattijs <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 | 95 +++++++++++++++---- .../uniformFixedValuePointPatchField.H | 30 +++++- .../uniformFixedValuePointPatchFields.C | 0 .../uniformFixedValuePointPatchFields.H | 0 .../PatchFunction1/PatchFunction1New.C | 3 +- 7 files changed, 109 insertions(+), 21 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 8bc7b414da7..127e91e270c 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 3f43482922a..f9ba08367cc 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 28ce8e1c0fd..3b51496edce 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<class Type> +const Foam::polyPatch& +Foam::uniformFixedValuePointPatchField<Type>::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<Type>(p, iF, dict, false), - uniformValue_(Function1<Type>::New("uniformValue", dict)) + uniformValue_ + ( + PatchFunction1<Type>::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<Type>::operator=(uniformValue_->value(t)); + this->evaluate(); } } @@ -80,11 +109,18 @@ uniformFixedValuePointPatchField ) : fixedValuePointPatchField<Type>(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<Type>::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<Type>(ptf), - uniformValue_(ptf.uniformValue_.clone()) + uniformValue_(ptf.uniformValue_.clone(this->getPatch(this->patch()))) {} @@ -109,15 +145,44 @@ uniformFixedValuePointPatchField ) : fixedValuePointPatchField<Type>(ptf, iF), - uniformValue_(ptf.uniformValue_.clone()) + uniformValue_(ptf.uniformValue_.clone(this->getPatch(this->patch()))) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +void Foam::uniformFixedValuePointPatchField<Type>::autoMap +( + const pointPatchFieldMapper& mapper +) { - // For safety re-evaluate - const scalar t = this->db().time().timeOutputValue(); - fixedValuePointPatchField<Type>::operator==(uniformValue_->value(t)); + fixedValuePointPatchField<Type>::autoMap(mapper); + uniformValue_().autoMap(mapper); + + if (uniformValue_().constant()) + { + // If mapper is not dependent on time we're ok to evaluate + this->evaluate(); + } } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template<class Type> +void Foam::uniformFixedValuePointPatchField<Type>::rmap +( + const pointPatchField<Type>& ptf, + const labelList& addr +) +{ + fixedValuePointPatchField<Type>::rmap(ptf, addr); + + const uniformFixedValuePointPatchField& tiptf = + refCast<const uniformFixedValuePointPatchField>(ptf); + + uniformValue_().rmap(tiptf.uniformValue_(), addr); +} + template<class Type> void Foam::uniformFixedValuePointPatchField<Type>::updateCoeffs() @@ -126,10 +191,8 @@ void Foam::uniformFixedValuePointPatchField<Type>::updateCoeffs() { return; } - const scalar t = this->db().time().timeOutputValue(); fixedValuePointPatchField<Type>::operator==(uniformValue_->value(t)); - fixedValuePointPatchField<Type>::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 3ede9eba71c..31bc640cb67 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<Type> { + // Private Member Functions + + static const polyPatch& getPatch(const pointPatch&); + + // Private data - autoPtr<Function1<Type>> uniformValue_; + autoPtr<PatchFunction1<Type>> 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<Type>&, + 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 1b825980bcc..d75d23c4f11 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1New.C +++ b/src/meshTools/PatchFunction1/PatchFunction1New.C @@ -102,7 +102,8 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New pp, PatchFunction1Types::ConstantField<Type>::typeName, entryName, - dict + dict, + faceValues ) ); } -- GitLab