diff --git a/applications/test/codeStream/codeStreamDict1 b/applications/test/codeStream/codeStreamDict1 index 8360f3ff4f7b3756b98eb921e46bb9c4951c091f..a552f5ec68d23acf9a1b7ed919a8550ac1db78e1 100644 --- a/applications/test/codeStream/codeStreamDict1 +++ b/applications/test/codeStream/codeStreamDict1 @@ -30,7 +30,8 @@ writeInterval #codeStream codeOptions #{ - -I$(LIB_SRC)/finiteVolume/lnInclude + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude #}; localCode diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C index 17aad06a00d094e328a856718d6c117649791f69..e2583450f31965c1176f4524144634a0cf3cf843 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,6 +30,7 @@ License #include "dlLibraryTable.H" #include "PstreamReduceOps.H" #include "OSspecific.H" +#include "Ostream.H" #include "regIOobject.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -42,6 +43,45 @@ namespace Foam // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +namespace Foam +{ +//! \cond fileScope +static inline void writeEntryIfPresent +( + Ostream& os, + const dictionary& dict, + const word& key +) +{ + // non-recursive like dictionary::found, but no pattern-match either + const entry* ptr = dict.lookupEntryPtr(key, false, false); + + if (ptr) + { + os.writeKeyword(key) + << token::HASH << token::BEGIN_BLOCK; + + os.writeQuoted(string(ptr->stream()), false) + << token::HASH << token::END_BLOCK + << token::END_STATEMENT << nl; + } +} +//! \endcond +} + + +void Foam::codedBase::writeCodeDict(Ostream& os, const dictionary& dict) +{ + writeEntryIfPresent(os, dict, "codeInclude"); + writeEntryIfPresent(os, dict, "localCode"); + writeEntryIfPresent(os, dict, "code"); + writeEntryIfPresent(os, dict, "codeOptions"); + writeEntryIfPresent(os, dict, "codeLibs"); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + void* Foam::codedBase::loadLibrary ( const fileName& libPath, @@ -165,8 +205,6 @@ void Foam::codedBase::unloadLibrary } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - void Foam::codedBase::createLibrary ( dynamicCode& dynCode, diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H index 8ac7114ce67c12b1c9b145de7b854efa5e48df50..1c03e71c092007813f588b5aa3b6b3251cb76602 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,6 +43,7 @@ namespace Foam { // Forward declaration of classes +class Ostream; class dynamicCode; class dynamicCodeContext; class dlLibraryTable; @@ -83,14 +84,17 @@ class codedBase void createLibrary(dynamicCode&, const dynamicCodeContext&) const; //- Disallow default bitwise copy construct - codedBase(const codedBase&); + codedBase(const codedBase&) = delete; //- Disallow default bitwise assignment - void operator=(const codedBase&); + void operator=(const codedBase&) = delete; protected: + //- Write code-dictionary contents + static void writeCodeDict(Ostream&, const dictionary&); + //- Update library as required void updateLibrary ( diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C index f56a8cf1e708dfad82db96c510e10aa6b85ffb00..a840d794822bf3597cd7f29507a4e5b0afc5afdc 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/codedFixedValue/codedFixedValuePointPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -331,55 +331,7 @@ void Foam::codedFixedValuePointPatchField<Type>::write(Ostream& os) const os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT << nl; - if (dict_.found("codeInclude")) - { - os.writeKeyword("codeInclude") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeInclude"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - os.writeKeyword("localCode") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["localCode"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - os.writeKeyword("code") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["code"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - os.writeKeyword("codeOptions") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeOptions"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - os.writeKeyword("codeLibs") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeLibs"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } + codedBase::writeCodeDict(os, dict_); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.C index 5432ece12f17da1bd769826dfc335f5e3ede871f..22a1e1b0f78eac1631b19d8594f39c8f513635cf 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.C @@ -118,6 +118,12 @@ Foam::genericPolyPatch::~genericPolyPatch() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +const Foam::word& Foam::genericPolyPatch::actualType() const +{ + return actualTypeName_; +} + + void Foam::genericPolyPatch::write(Ostream& os) const { os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl; diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.H index 6a22d8af6f504cf9ef1c0e4d61323112403a4702..ac412bcae005fdff9695aeb4f9a639fe572dab1f 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/basic/generic/genericPolyPatch.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,8 +25,9 @@ Class Foam::genericPolyPatch Description - Substitute for unknown patches. Used for postprocessing when only - basic polyPatch info is needed. + Substitute for unknown patches. + Used for postprocessing when only basic polyPatch info is needed + or if the real patch type is unavailable. Note Storage is not optimal. It stores all face centres and cells on all @@ -57,7 +58,7 @@ class genericPolyPatch { // Private data - word actualTypeName_; + const word actualTypeName_; dictionary dict_; public: @@ -162,6 +163,9 @@ public: // Member functions + //- Return the actual type + const word& actualType() const; + //- Write the polyPatch data as a dictionary virtual void write(Ostream&) const; }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index cfd6945420321bb39d23272b8c70e030414a8f4b..5771972313a2333218f602dd88049f36a80bdc10 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -329,55 +329,7 @@ void Foam::codedFixedValueFvPatchField<Type>::write(Ostream& os) const os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT << nl; - if (dict_.found("codeInclude")) - { - os.writeKeyword("codeInclude") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeInclude"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - os.writeKeyword("localCode") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["localCode"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - os.writeKeyword("code") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["code"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - os.writeKeyword("codeOptions") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeOptions"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - os.writeKeyword("codeLibs") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeLibs"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } + codedBase::writeCodeDict(os, dict_); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C index d1b53e144dbbc2c228cc8395d62b5dd0b9c6a23c..450aa8b9e623097315e488fd6dc2bed8b6668ec8 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedMixed/codedMixedFvPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -341,55 +341,7 @@ void Foam::codedMixedFvPatchField<Type>::write(Ostream& os) const os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT << nl; - if (dict_.found("codeInclude")) - { - os.writeKeyword("codeInclude") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeInclude"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("localCode")) - { - os.writeKeyword("localCode") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["localCode"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("code")) - { - os.writeKeyword("code") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["code"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeOptions")) - { - os.writeKeyword("codeOptions") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeOptions"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } - - if (dict_.found("codeLibs")) - { - os.writeKeyword("codeLibs") - << token::HASH << token::BEGIN_BLOCK; - - os.writeQuoted(string(dict_["codeLibs"]), false) - << token::HASH << token::END_BLOCK - << token::END_STATEMENT << nl; - } + codedBase::writeCodeDict(os, dict_); } diff --git a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C index 374aa5eac6cd7bedc586b7653846a152b1d48153..52378876442ee0a465821868391f1287c0ba5d9f 100644 --- a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C +++ b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.C @@ -764,6 +764,13 @@ Foam::genericFvPatchField<Type>::gradientBoundaryCoeffs() const } +template<class Type> +const Foam::word& Foam::genericFvPatchField<Type>::actualType() const +{ + return actualTypeName_; +} + + template<class Type> void Foam::genericFvPatchField<Type>::write(Ostream& os) const { diff --git a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.H b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.H index ec3be385b42172f4d6d0f63a48b1ad77890eec05..88091b90bbe277ca242405559d715af3a05edbd4 100644 --- a/src/genericPatchFields/genericFvPatchField/genericFvPatchField.H +++ b/src/genericPatchFields/genericFvPatchField/genericFvPatchField.H @@ -59,7 +59,7 @@ class genericFvPatchField { // Private data - word actualTypeName_; + const word actualTypeName_; dictionary dict_; HashPtrTable<scalarField> scalarFields_; @@ -179,6 +179,9 @@ public: tmp<Field<Type>> gradientBoundaryCoeffs() const; + //- Return the actual type + const word& actualType() const; + //- Write virtual void write(Ostream&) const; }; diff --git a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C index 8f4970855f4fedd51c8f6d90fbac4d44a1757b50..c1d1dd42ecd017179bb1bfbf9f5261317f2a7f25 100644 --- a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C +++ b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -557,6 +557,13 @@ void Foam::genericPointPatchField<Type>::rmap } +template<class Type> +const Foam::word& Foam::genericPointPatchField<Type>::actualType() const +{ + return actualTypeName_; +} + + template<class Type> void Foam::genericPointPatchField<Type>::write(Ostream& os) const { diff --git a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.H b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.H index e68ce631b13cc342766c0ae6b7fcadd1a8b046f7..33880fd72326aa58d7697785f4930a56c94bc92f 100644 --- a/src/genericPatchFields/genericPointPatchField/genericPointPatchField.H +++ b/src/genericPatchFields/genericPointPatchField/genericPointPatchField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,7 +55,7 @@ class genericPointPatchField { // Private data - word actualTypeName_; + const word actualTypeName_; dictionary dict_; HashPtrTable<scalarField> scalarFields_; @@ -151,6 +151,9 @@ public: ); + //- Return the actual type + const word& actualType() const; + //- Write virtual void write(Ostream&) const; };