diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index 31ad1b2286..d303761a7f 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -176,46 +176,69 @@ Foam::Field::Field } +template +Foam::Field::Field(const entry& e, const label len) +{ + assign(e, len); +} + + template Foam::Field::Field ( const word& keyword, const dictionary& dict, - const label len + const label len, + enum keyType::option matchOpt ) +{ + assign(keyword, dict, len, matchOpt); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::Field::assign(const entry& e, const label len) { if (len) { - ITstream& is = dict.lookup(keyword); + ITstream& is = e.stream(); // Read first token token firstToken(is); if (firstToken.isWord("uniform")) { - this->resize(len); + // Resize to expected length (or -1 : retain current length) + if (len >= 0) + { + this->resize(len); + } operator=(pTraits(is)); } else if (firstToken.isWord("nonuniform")) { is >> static_cast&>(*this); const label lenRead = this->size(); - if (len != lenRead) + + // Check lengths + if (len >= 0 && len != lenRead) { if (len < lenRead && allowConstructFromLargerSize) { + // Truncate the data + this->resize(len); + #ifdef FULLDEBUG - IOWarningInFunction(dict) + IOWarningInFunction(is) << "Sizes do not match. Truncating " << lenRead << " entries to " << len << endl; #endif - - // Truncate the data - this->resize(len); } else { - FatalIOErrorInFunction(dict) + FatalIOErrorInFunction(is) << "size " << lenRead << " is not equal to the expected length " << len << exit(FatalIOError); @@ -224,7 +247,7 @@ Foam::Field::Field } else { - FatalIOErrorInFunction(dict) + FatalIOErrorInFunction(is) << "Expected keyword 'uniform' or 'nonuniform', found " << firstToken.info() << nl << exit(FatalIOError); @@ -233,7 +256,21 @@ Foam::Field::Field } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::Field::assign +( + const word& keyword, + const dictionary& dict, + const label len, + enum keyType::option matchOpt +) +{ + if (len) + { + assign(dict.lookupEntry(keyword, matchOpt), len); + } +} + template void Foam::Field::map @@ -246,7 +283,7 @@ void Foam::Field::map if (f.size() != mapAddressing.size()) { - f.setSize(mapAddressing.size()); + f.resize(mapAddressing.size()); } if (mapF.size() > 0) @@ -288,7 +325,7 @@ void Foam::Field::map if (f.size() != mapAddressing.size()) { - f.setSize(mapAddressing.size()); + f.resize(mapAddressing.size()); } if (mapWeights.size() != mapAddressing.size()) @@ -363,7 +400,7 @@ void Foam::Field::map // from distribution. Note: this behaviour is different compared // to local mapper. this->transfer(newMapF); - this->setSize(mapper.size()); + this->resize(mapper.size()); } } else @@ -435,7 +472,7 @@ void Foam::Field::autoMap // from distribution. Note: this behaviour is different compared // to local mapper. this->transfer(fCpy); - this->setSize(mapper.size()); + this->resize(mapper.size()); } } else @@ -455,7 +492,7 @@ void Foam::Field::autoMap } else { - this->setSize(mapper.size()); + this->resize(mapper.size()); } } } diff --git a/src/OpenFOAM/fields/Fields/Field/Field.H b/src/OpenFOAM/fields/Fields/Field/Field.H index 8ea04193fb..7ab65e03f6 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.H +++ b/src/OpenFOAM/fields/Fields/Field/Field.H @@ -37,6 +37,7 @@ SourceFiles FieldI.H FieldM.H Field.C + FieldBase.C FieldFunctions.C FieldFunctionsM.C @@ -48,8 +49,8 @@ SourceFiles #include "tmp.H" #include "direction.H" #include "labelList.H" +#include "keyType.H" #include "scalarList.H" -#include "FieldBase.H" #include "VectorSpace.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -60,15 +61,44 @@ namespace Foam // Forward Declarations class FieldMapper; class dictionary; +class entry; template class Field; template class SubField; -template -Ostream& operator<<(Ostream&, const Field&); +template Ostream& operator<<(Ostream&, const Field&); +template Ostream& operator<<(Ostream&, const tmp>&); -template -Ostream& operator<<(Ostream&, const tmp>&); + +/*---------------------------------------------------------------------------*\ + Class FieldBase Declaration +\*---------------------------------------------------------------------------*/ + +//- Template invariant parts for Field and SubField +class FieldBase +: + public refCount +{ +public: + + // Static Data Members + + //- Typename for Field + static const char* const typeName; + + //- Permit read construct from a larger size. + // Mostly required for things like column mesh, for example. + static bool allowConstructFromLargerSize; + + + // Constructors + + //- Default construct + constexpr FieldBase() noexcept + : + refCount() + {} +}; /*---------------------------------------------------------------------------*\ @@ -234,8 +264,18 @@ public: //- Construct from Istream inline Field(Istream& is); - //- Construct from a dictionary entry - Field(const word& keyword, const dictionary& dict, const label len); + //- Construct from a dictionary (primitive) entry + Field(const entry& e, const label len); + + //- Construct from lookup of a dictionary (primitive) entry. + // Uses REGEX lookup for legacy compatibility. + Field + ( + const word& keyword, + const dictionary& dict, + const label len, + enum keyType::option matchOpt = keyType::REGEX + ); //- Clone inline tmp> clone() const; @@ -257,6 +297,19 @@ public: // Member Functions + //- Assign from a dictionary (primitive) entry + void assign(const entry& e, const label len); + + //- Assign from lookup of a dictionary (primitive) entry + // Uses REGEX lookup for legacy compatibility. + void assign + ( + const word& keyword, + const dictionary& dict, + const label len, + enum keyType::option matchOpt = keyType::REGEX + ); + //- 1 to 1 map from the given field void map ( diff --git a/src/OpenFOAM/fields/Fields/Field/FieldBase.C b/src/OpenFOAM/fields/Fields/Field/FieldBase.C index 992b55dde0..fdbbb1e94b 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldBase.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldBase.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,9 +25,9 @@ License \*---------------------------------------------------------------------------*/ -#include "FieldBase.H" +#include "Field.H" -// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::FieldBase::typeName("Field"); diff --git a/src/OpenFOAM/fields/Fields/Field/FieldBase.H b/src/OpenFOAM/fields/Fields/Field/FieldBase.H index c603acd311..7cec1b4541 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldBase.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldBase.H @@ -1,83 +1 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | www.openfoam.com - \\/ M anipulation | -------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - Foam::FieldBase - -Description - Template invariant parts for Field and SubField - -SourceFiles - FieldBase.C - -\*---------------------------------------------------------------------------*/ - -#ifndef FieldBase_H -#define FieldBase_H - -#include "refCount.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class FieldBase Declaration -\*---------------------------------------------------------------------------*/ - -class FieldBase -: - public refCount -{ -public: - - // Static Data Members - - //- Typename for Field - static const char* const typeName; - - //- Permit read construct from a larger size. - // Mostly required for things like column mesh, for example. - static bool allowConstructFromLargerSize; - - - // Constructors - - //- Default construct, refCount zero - constexpr FieldBase() noexcept - : - refCount() - {} -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -#endif - -// ************************************************************************* // +#warning File removed - left for old dependency check only diff --git a/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C index 4be69297f8..775710af15 100644 --- a/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,12 +55,11 @@ Foam::valuePointPatchField::valuePointPatchField pointPatchField(p, iF, dict), Field(p.size()) { - if (dict.found("value")) + const auto* eptr = dict.findEntry("value", keyType::LITERAL); + + if (eptr) { - Field::operator= - ( - Field("value", dict, p.size()) - ); + Field::assign(*eptr, p.size()); } else if (!valueRequired) { diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.H b/src/OpenFOAM/primitives/strings/keyType/keyType.H index bcba95958d..eee39e55cd 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.H @@ -40,8 +40,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef keyType_H -#define keyType_H +#ifndef Foam_keyType_H +#define Foam_keyType_H #include "word.H" #include "wordRe.H" diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C index 8481c191de..e2376aef73 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C @@ -98,16 +98,15 @@ Foam::faPatchField::faPatchField /// if (valueRequired) - not yet needed. Already a lazy evaluation - if (dict.found("value")) + const auto* eptr = dict.findEntry("value", keyType::LITERAL); + + if (eptr) { - faPatchField::operator= - ( - Field("value", dict, p.size()) - ); + Field::assign(*eptr, p.size()); } else { - faPatchField::operator=(pTraits::zero); + Field::operator=(Zero); } } diff --git a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C index 8a2411b483..673bea130a 100644 --- a/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C +++ b/src/finiteArea/fields/faePatchFields/faePatchField/faePatchField.C @@ -84,16 +84,15 @@ Foam::faePatchField::faePatchField patch_(p), internalField_(iF) { - if (dict.found("value")) + const auto* eptr = dict.findEntry("value", keyType::LITERAL); + + if (eptr) { - faePatchField::operator= - ( - Field("value", dict, p.size()) - ); + Field::assign(*eptr, p.size()); } else { - faePatchField::operator=(pTraits::zero); + Field::operator=(Zero); } } diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C index af1946f534..ded2e52eb7 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C @@ -127,12 +127,11 @@ Foam::fvPatchField::fvPatchField if (valueRequired) { - if (dict.found("value")) + const auto* eptr = dict.findEntry("value", keyType::LITERAL); + + if (eptr) { - Field::operator= - ( - Field("value", dict, p.size()) - ); + Field::assign(*eptr, p.size()); } else { diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C index 3d37d8c251..b4c20b8c92 100644 --- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C +++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchField.C @@ -91,12 +91,11 @@ Foam::fvsPatchField::fvsPatchField { if (valueRequired) { - if (dict.found("value")) + const auto* eptr = dict.findEntry("value", keyType::LITERAL); + + if (eptr) { - fvsPatchField::operator= - ( - Field("value", dict, p.size()) - ); + Field::assign(*eptr, p.size()); } else {