From 9461d950d2ae9e69e9153e2e7397dcc211ef2da5 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Thu, 7 Feb 2019 10:33:46 +0000 Subject: [PATCH] ENH: PatchFunction1: work with points. See 1046. --- .../ConstantField/ConstantField.C | 39 +++++++++++++++++-- .../PatchFunction1/PatchFunction1New.C | 8 +++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C index 6815159711a..5ef4d1d974c 100644 --- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C +++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,7 +43,22 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField isUniform_(isUniform), uniformValue_(uniformValue), value_(nonUniformValue) -{} +{ + if (faceValues && nonUniformValue.size() != pp.size()) + { + FatalIOErrorInFunction(dict) + << "Supplied field size " << nonUniformValue.size() + << " is not equal to the number of faces " << pp.size() + << " of patch " << pp.name() << exit(FatalIOError); + } + else if (!faceValues && nonUniformValue.size() != pp.nPoints()) + { + FatalIOErrorInFunction(dict) + << "Supplied field size " << nonUniformValue.size() + << " is not equal to the number of points " << pp.nPoints() + << " of patch " << pp.name() << exit(FatalIOError); + } +} template<class Type> @@ -132,6 +147,7 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue fld = uniformValue; } } + return fld; } @@ -147,7 +163,17 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField ) : PatchFunction1<Type>(pp, entryName, dict, faceValues), - value_(getValue(entryName, dict, pp.size(), isUniform_, uniformValue_)) + value_ + ( + getValue + ( + entryName, + dict, + (faceValues ? pp.size() : pp.nPoints()), + isUniform_, + uniformValue_ + ) + ) {} @@ -177,7 +203,12 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField value_(cnst.value_) { // If different sizes do what? - value_.setSize(this->patch_.size()); + value_.setSize + ( + this->faceValues_ + ? this->patch_.size() + : this->patch_.nPoints() + ); if (isUniform_) { value_ = uniformValue_; diff --git a/src/meshTools/PatchFunction1/PatchFunction1New.C b/src/meshTools/PatchFunction1/PatchFunction1New.C index 4b10bd59ca2..1b825980bcc 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1New.C +++ b/src/meshTools/PatchFunction1/PatchFunction1New.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,7 +69,11 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New is.putBack(firstToken); const Type uniformValue = pTraits<Type>(is); - const Field<Type> value(pp.size(), uniformValue); + const Field<Type> value + ( + (faceValues ? pp.size() : pp.nPoints()), + uniformValue + ); return autoPtr<PatchFunction1<Type>> ( -- GitLab