From 6f2376a649d8663e17c56c5d6ff929b3dfa05670 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 30 Oct 2018 13:26:23 +0000 Subject: [PATCH] ENH: ConstantField: allow 'constant' keyword. See #1046. --- .../ConstantField/ConstantField.C | 50 ++++++++++++++++++- .../ConstantField/ConstantField.H | 12 ++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C index a6afaa09f4..dc7ad608aa 100644 --- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C +++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C @@ -42,6 +42,54 @@ Foam::PatchFunction1Types::ConstantField::ConstantField {} +template +Foam::Field Foam::PatchFunction1Types::ConstantField::getValue +( + const word& keyword, + const dictionary& dict, + const label len +) +{ + Field fld; + + if (len) + { + ITstream& is = dict.lookup(keyword); + + // Read first token + token firstToken(is); + + if (firstToken.isWord()) + { + if + ( + firstToken.wordToken() == "uniform" + || firstToken.wordToken() == "constant" + ) + { + fld.setSize(len); + fld = pTraits(is); + } + else + { + FatalIOErrorInFunction(dict) + << "expected keyword 'uniform' or 'constant', found " + << firstToken.wordToken() + << exit(FatalIOError); + } + } + else + { + fld.setSize(len); + + is.putBack(firstToken); + fld = pTraits(is); + } + } + return fld; +} + + template Foam::PatchFunction1Types::ConstantField::ConstantField ( @@ -52,7 +100,7 @@ Foam::PatchFunction1Types::ConstantField::ConstantField ) : PatchFunction1(pp, entryName, dict, faceValues), - value_(entryName, dict, pp.size()) + value_(getValue(entryName, dict, pp.size())) {} diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.H b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H index 703cfc49c1..c9eeea67f8 100644 --- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.H +++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,6 +66,14 @@ class ConstantField // Private Member Functions + //- Helper to read value from dictionary + static Field getValue + ( + const word& keyword, + const dictionary& dict, + const label len + ); + //- No copy assignment void operator=(const ConstantField&) = delete;