From 04a985ccb314e604730e8dd6183f5d12b9c77485 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 30 Oct 2018 13:37:54 +0000 Subject: [PATCH] ENH: ConstantField: allow nonuniform. See #1046. --- .../ConstantField/ConstantField.C | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C index dc7ad608aa..ee0a20229d 100644 --- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C +++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C @@ -70,11 +70,44 @@ Foam::Field Foam::PatchFunction1Types::ConstantField::getValue fld.setSize(len); fld = pTraits(is); } + else if (firstToken.wordToken() == "nonuniform") + { + List& list = fld; + is >> list; + label currentSize = fld.size(); + if (currentSize != len) + { + if + ( + len < currentSize + && FieldBase::allowConstructFromLargerSize + ) + { + #ifdef FULLDEBUG + IOWarningInFunction(dict) + << "Sizes do not match. " + << "Re-sizing " << currentSize + << " entries to " << len + << endl; + #endif + + // Resize the data + fld.setSize(len); + } + else + { + FatalIOErrorInFunction(dict) + << "size " << fld.size() + << " is not equal to the given value of " << len + << exit(FatalIOError); + } + } + } else { FatalIOErrorInFunction(dict) - << "expected keyword 'uniform' or 'constant', found " - << firstToken.wordToken() + << "expected keyword 'uniform', 'nonuniform' or 'constant'" + << ", found " << firstToken.wordToken() << exit(FatalIOError); } }