mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: namedDictionary for managing keyword/dictionary combinations
- reworked from the openfoam.org wordAndDictionary version. Allows, for example, named entries in topoSet.
This commit is contained in:
3
applications/test/namedDictionary/Make/files
Normal file
3
applications/test/namedDictionary/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-namedDictionary.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-namedDictionary
|
||||
2
applications/test/namedDictionary/Make/options
Normal file
2
applications/test/namedDictionary/Make/options
Normal file
@ -0,0 +1,2 @@
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
||||
84
applications/test/namedDictionary/Test-namedDictionary.C
Normal file
84
applications/test/namedDictionary/Test-namedDictionary.C
Normal file
@ -0,0 +1,84 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-namedDictionary
|
||||
|
||||
Description
|
||||
Test handling of keyType/dictionary
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "IOstreams.H"
|
||||
#include "IOobject.H"
|
||||
#include "IFstream.H"
|
||||
#include "namedDictionary.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noBanner();
|
||||
argList::noParallel();
|
||||
argList::addArgument("file1 .. fileN");
|
||||
argList args(argc, argv, false, true);
|
||||
|
||||
if (args.size() <= 1)
|
||||
{
|
||||
InfoErr<< "Provide a file or files to test" << nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (label argi=1; argi < args.size(); ++argi)
|
||||
{
|
||||
const auto dictFile = args.get<fileName>(argi);
|
||||
IFstream ifs(dictFile);
|
||||
|
||||
dictionary dict(ifs);
|
||||
|
||||
IOobject::writeDivider(Info) << nl;
|
||||
|
||||
for (const entry& dEntry : dict)
|
||||
{
|
||||
if (!dEntry.isStream())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Info<< "input: " << dEntry << nl;
|
||||
List<namedDictionary> list(dEntry.stream());
|
||||
Info<< "list: " << list << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
83
applications/test/namedDictionary/testDict1
Normal file
83
applications/test/namedDictionary/testDict1
Normal file
@ -0,0 +1,83 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: v2012 |
|
||||
| \\ / A nd | Website: www.openfoam.com |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class dictionary;
|
||||
object dictionary;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
entry1
|
||||
(
|
||||
value1
|
||||
value2 ; // spurious trailing ';' is removed
|
||||
this { correct true; }
|
||||
|
||||
{ } // Empty everything == ignore
|
||||
|
||||
{ anonymous true; }
|
||||
);
|
||||
|
||||
|
||||
actions1
|
||||
(
|
||||
starting
|
||||
{
|
||||
name self;
|
||||
type faceSet;
|
||||
action new;
|
||||
source something;
|
||||
}
|
||||
|
||||
{
|
||||
name self;
|
||||
type faceSet;
|
||||
action subset;
|
||||
source something;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
actions2
|
||||
(
|
||||
{
|
||||
name self;
|
||||
type faceSet;
|
||||
action new;
|
||||
source something;
|
||||
}
|
||||
|
||||
{
|
||||
name self;
|
||||
type faceSet;
|
||||
action subset;
|
||||
source something;
|
||||
}
|
||||
);
|
||||
|
||||
actions3
|
||||
(
|
||||
{
|
||||
name self;
|
||||
type faceSet;
|
||||
action new;
|
||||
source something;
|
||||
}
|
||||
|
||||
subset
|
||||
{
|
||||
name self;
|
||||
type faceSet;
|
||||
action subset;
|
||||
source something;
|
||||
}
|
||||
);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -47,6 +47,7 @@ Description
|
||||
#include "faceZoneSet.H"
|
||||
#include "pointZoneSet.H"
|
||||
#include "IOdictionary.H"
|
||||
#include "namedDictionary.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -237,7 +238,7 @@ int main(int argc, char *argv[])
|
||||
IOdictionary topoSetDict(dictIO);
|
||||
|
||||
// Read set construct info from dictionary
|
||||
PtrList<dictionary> actions(topoSetDict.lookup("actions"));
|
||||
List<namedDictionary> actionEntries(topoSetDict.lookup("actions"));
|
||||
|
||||
forAll(timeDirs, timeI)
|
||||
{
|
||||
@ -248,8 +249,13 @@ int main(int argc, char *argv[])
|
||||
meshReadUpdate(mesh);
|
||||
|
||||
// Execute all actions
|
||||
for (const dictionary& dict : actions)
|
||||
for (const namedDictionary& actionEntry : actionEntries)
|
||||
{
|
||||
const dictionary& dict = actionEntry.dict();
|
||||
if (dict.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const word setName(dict.get<word>("name"));
|
||||
const word setType(dict.get<word>("type"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user