Commit d0795abc authored by Mark Olesen's avatar Mark Olesen
Browse files

Merge commit 'bundle/home' into olesenm

parents 394fcb56 3d689522
......@@ -30,6 +30,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "IOstreams.H"
#include "IOobject.H"
#include "IFstream.H"
#include "dictionary.H"
......@@ -40,18 +41,12 @@ using namespace Foam;
int main(int argc, char *argv[])
{
IFstream dictStream("testDict");
dictionary testDict(dictStream);
Info<< dictionary(IFstream("testDict")()) << endl;
Info<< testDict << endl;
IOobject::writeDivider(Info);
{
dictionary someDict;
someDict.add(keyType("a.*", true), "subdictValue");
dictionary dict;
dict.add("someDict", someDict);
dict.add(keyType(".*", true), "parentValue");
dictionary dict(IFstream("testDictRegex")());
Info<< "dict:" << dict << endl;
......@@ -64,6 +59,18 @@ int main(int argc, char *argv[])
Info<< "Recursive wildcard find \"def\" in sub directory : "
<< dict.subDict("someDict").lookup("def", true)
<< endl;
Info<< "Recursive wildcard find \"foo\" in sub directory : "
<< dict.subDict("someDict").lookup("foo", true)
<< endl;
Info<< "Recursive wildcard find \"fooz\" in sub directory : "
<< dict.subDict("someDict").lookup("fooz", true)
<< endl;
Info<< "Recursive wildcard find \"bar\" in sub directory : "
<< dict.subDict("someDict").lookup("bar", true)
<< endl;
Info<< "Recursive wildcard find \"xxx\" in sub directory : "
<< dict.subDict("someDict").lookup("xxx", true)
<< endl;
}
return 0;
......
/*-------------------------------*- C++ -*---------------------------------*\
| ========= |
| \\ / OpenFOAM |
| \\ / |
| \\ / The Open Source CFD Toolbox |
| \\/ http://www.OpenFOAM.org |
\*-------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object testDictRegex;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#inputMode merge
".*" parentValue1;
"[n-z].*" parentValue2;
"f.*" parentValue3;
someDict
{
foo subdictValue0;
bar $f.*; // should this really match 'foo'?
// result is dependent on insert order!
"a.*c" subdictValue3;
"ab.*" subdictValue2;
"a.*" subdictValue1;
abcd subdictValue4;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
foamUpgradeFvSolution.C
EXE = $(FOAM_APPBIN)/foamUpgradeFvSolution
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
foamUpgradeFvSolution
Description
Simple tool to upgrade the syntax of system/fvSolution::solvers
Usage
- foamUpgradeFvSolution [OPTION]
@param -test \n
Suppress writing the updated fvSolution file
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "IOdictionary.H"
#include "solution.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validOptions.insert("test", "");
# include "setRootCase.H"
# include "createTime.H"
IOdictionary solutionDict
(
IOobject
(
"fvSolution",
runTime.system(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
label nChanged = 0;
entry* e = solutionDict.lookupEntryPtr("solvers", false, false);
if (e && e->isDict())
{
nChanged = solution::upgradeSolverDict(e->dict(), true);
}
Info<< nChanged << " solver settings changed" << nl << endl;
if (nChanged)
{
if (args.options().found("test"))
{
Info<< "-test option: no changes made" << nl << endl;
}
else
{
mv
(
solutionDict.objectPath(),
solutionDict.objectPath() + ".old"
);
solutionDict.regIOobject::write();
Info<< "Backup to " << (solutionDict.objectPath() + ".old") << nl
<< "Write to " << solutionDict.objectPath() << nl << endl;
}
}
return 0;
}
// ************************************************************************* //
......@@ -697,7 +697,7 @@ bool Foam::dictionary::changeKeyword
IDLList<entry>::replace(iter2(), iter());
delete iter2();
hashedEntries_.erase(iter2);
}
else
{
......
......@@ -163,16 +163,16 @@ public:
dictionary(Istream&);
//- Construct as copy given the parent dictionary
dictionary(const dictionary& parentDict, const dictionary& dict);
dictionary(const dictionary& parentDict, const dictionary&);
//- Construct top-level dictionary as copy
dictionary(const dictionary& dict);
dictionary(const dictionary&);
//- Construct and return clone
Foam::autoPtr<dictionary> clone() const;
//- Construct top-level dictionary on freestore from Istream
static Foam::autoPtr<dictionary> New(Istream& is);
static Foam::autoPtr<dictionary> New(Istream&);
// Destructor
......@@ -211,12 +211,12 @@ public:
//- Search dictionary for given keyword
// If recursive search parent dictionaries
bool found(const word& keyword, bool recursive=false) const;
bool found(const word&, bool recursive=false) const;
//- Find and return an entry data stream pointer if present
// otherwise return NULL.
// If recursive search parent dictionaries. If wildCardMatch
// use wildcards.
// If recursive search parent dictionaries.
// If wildCardMatch use wildcards.
const entry* lookupEntryPtr
(
const word&,
......@@ -226,8 +226,8 @@ public:
//- Find and return an entry data stream pointer for manipulation
// if present otherwise return NULL.
// If recursive search parent dictionaries. If wildCardMatch
// use wildcards.
// If recursive search parent dictionaries.
// If wildCardMatch use wildcards.
entry* lookupEntryPtr
(
const word&,
......@@ -236,8 +236,8 @@ public:
);
//- Find and return an entry data stream if present otherwise error.
// If recursive search parent dictionaries. If wildCardMatch
// use wildcards.
// If recursive search parent dictionaries.
// If wildCardMatch use wildcards.
const entry& lookupEntry
(
const word&,
......@@ -331,13 +331,13 @@ public:
//- Add a scalar entry
// optionally overwrite an existing entry
void add (const keyType&, const scalar, bool overwrite=false);
void add(const keyType&, const scalar, bool overwrite=false);
//- Add a dictionary entry
// optionally merge with an existing sub-dictionary
void add
(
const keyType& keyword,
const keyType&,
const dictionary&,
bool mergeEntry=false
);
......@@ -345,7 +345,7 @@ public:
//- Add a T entry
// optionally overwrite an existing entry
template<class T>
void add(const keyType& keyword, const T&, bool overwrite=false);
void add(const keyType&, const T&, bool overwrite=false);
//- Assign a new entry, overwrite any existing entry
void set(entry*);
......@@ -354,14 +354,14 @@ public:
void set(const entry&);
//- Assign a dictionary entry, overwrite any existing entry
void set(const keyType& keyword, const dictionary&);
void set(const keyType&, const dictionary&);
//- Assign a T entry, overwrite any existing entry
template<class T>
void set(const keyType& keyword, const T&);
void set(const keyType&, const T&);
//- Remove an entry specified by keyword
bool remove(const word& keyword);
bool remove(const word&);
//- Change the keyword for an entry,
// optionally forcing overwrite of an existing entry
......@@ -369,7 +369,7 @@ public:
(
const keyType& oldKeyword,
const keyType& newKeyword,
bool forceOverwrite = false
bool forceOverwrite=false
);
//- Merge entries from the given dictionary.
......@@ -382,7 +382,7 @@ public:
// Write
void write(Ostream& os, bool subDict = true) const;
void write(Ostream&, bool subDict=true) const;
// Member Operators
......
......@@ -37,19 +37,17 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
SLList<string> argList::validArgs;
HashTable<string> argList::validOptions;
HashTable<string> argList::validParOptions;
}
Foam::SLList<Foam::string> Foam::argList::validArgs;
Foam::HashTable<Foam::string> Foam::argList::validOptions;
Foam::HashTable<Foam::string> Foam::argList::validParOptions;
bool Foam::argList::bannerEnabled(true);
Foam::argList::initValidTables::initValidTables()
{
validOptions.insert("case", "dir");
validOptions.insert("parallel", "");
validParOptions.insert("parallel", "");
validOptions.set("case", "dir");
validOptions.set("parallel", "");
validParOptions.set("parallel", "");
Pstream::addValidParOptions(validParOptions);
}
......@@ -138,7 +136,7 @@ void Foam::argList::getRootCase()
casePath = cwd();
// we could add this back in as '-case'?
// options_.insert("case", casePath);
// options_.set("case", casePath);
}
rootPath_ = casePath.path();
......@@ -285,7 +283,7 @@ Foam::argList::argList
string timeString = clock::clockTime();
// Print the banner once only for parallel runs
if (Pstream::master())
if (Pstream::master() && bannerEnabled)
{
IOobject::writeBanner(Info, true);
Info<< "Exec : " << argListString.c_str() << nl
......@@ -315,8 +313,6 @@ Foam::argList::argList
// For the master
if (Pstream::master())
{
fileNameList roots;
// establish rootPath_/globalCase_/case_ for master
getRootCase();
......@@ -333,45 +329,25 @@ Foam::argList::argList
<< exit(FatalError);
}
dictionary decompositionDict(decompDictStream);
Switch distributed(false);
if
(
decompositionDict.readIfPresent("distributed", distributed)
&& distributed
)
{
decompositionDict.lookup("roots") >> roots;
if (roots.size() != Pstream::nProcs()-1)
{
FatalError
<< "number of entries in decompositionDict::roots"
<< " is not equal to the number of slaves "
<< Pstream::nProcs()-1
<< exit(FatalError);
}
}
dictionary decompDict(decompDictStream);
label dictNProcs
(
readLabel
(
decompositionDict.lookup("numberOfSubdomains")
decompDict.lookup("numberOfSubdomains")
)
);
// Check number of processors. We have nProcs(number of
// actual processes), dictNProcs(wanted number of processes read
// from decompositionDict) and nProcDirs(number of processor
// directories - n/a when running distributed)
// Check number of processors.
// nProcs => number of actual procs
// dictNProcs => number of procs specified in decompositionDict
// nProcDirs => number of processor directories
// (n/a when running distributed)
//
// - normal running : nProcs = dictNProcs = nProcDirs
// - decomposition to more processors : nProcs = dictNProcs
// - decomposition to less processors : nProcs = nProcDirs
// - decomposition to more processors : nProcs = dictNProcs
// - decomposition to fewer processors : nProcs = nProcDirs
if (dictNProcs > Pstream::nProcs())
{
FatalError
......@@ -382,38 +358,23 @@ Foam::argList::argList
<< exit(FatalError);
}
if (!distributed && dictNProcs < Pstream::nProcs())
// distributed data
if (decompDict.lookupOrDefault<Switch>("distributed", false))
{
// Possibly going to fewer processors.
// Check if all procDirs are there.
label nProcDirs = 0;
while
(
dir
(
rootPath_/globalCase_/"processor"
+ name(++nProcDirs)
)
)
{}
fileNameList roots;
decompDict.lookup("roots") >> roots;
if (nProcDirs != Pstream::nProcs())
if (roots.size() != Pstream::nProcs()-1)
{
FatalError
<< "number of processor directories = "
<< nProcDirs
<< " is not equal to the number of processors = "
<< Pstream::nProcs()
<< "number of entries in decompositionDict::roots"
<< " is not equal to the number of slaves "
<< Pstream::nProcs()-1
<< exit(FatalError);
}
}
// distributed data
if (roots.size())
{
bool hadOptCase = options_.found("case");
// Distribute the master's argument list (with new root)
bool hadCaseOpt = options_.found("case");
for
(
int slave=Pstream::firstSlave();
......@@ -421,8 +382,7 @@ Foam::argList::argList
slave++
)
{
options_.erase("case");
options_.insert
options_.set
(
"case",
fileName(roots[slave-1])/globalCase_
......@@ -431,17 +391,42 @@ Foam::argList::argList
OPstream toSlave(Pstream::scheduled, slave);
toSlave << args_ << options_;
}
options_.erase("case");
// restore [-case dir]
if (hadOptCase)
if (hadCaseOpt)
{
options_.insert("case", rootPath_/globalCase_);
options_.set("case", rootPath_/globalCase_);
}
}
else
{
// Possibly going to fewer processors.
// Check if all procDirs are there.
if (dictNProcs < Pstream::nProcs())
{
label nProcDirs = 0;
while
(
dir
(
rootPath_/globalCase_/"processor"
+ name(++nProcDirs)
)
)
{}
if (nProcDirs != Pstream::nProcs())
{
FatalError
<< "number of processor directories = "
<< nProcDirs
<< " is not equal to the number of processors = "
<< Pstream::nProcs()
<< exit(FatalError);
}
}
// Distribute the master's argument list (unaltered)
for
(
......@@ -472,7 +457,6 @@ Foam::argList::argList
{
// establish rootPath_/globalCase_/case_
getRootCase();
case_ = globalCase_;
}
......@@ -510,21 +494,21 @@ Foam::argList::argList
}
if (Pstream::master())
if (Pstream::master() && bannerEnabled)
{
Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl
<< "nProcs : " << nProcs << endl;
}
if (parRunControl_.parRun() && Pstream::master())
{
Info<< "Slaves : " << slaveProcs << nl
<< "Pstream initialized with:" << nl
<< " floatTransfer : " << Pstream::floatTransfer << nl
<< " nProcsSimpleSum : " << Pstream::nProcsSimpleSum << nl
<< " commsType : "
<< Pstream::commsTypeNames[Pstream::defaultCommsType]
<< endl;
if (parRunControl_.parRun())
{
Info<< "Slaves : " << slaveProcs << nl
<< "Pstream initialized with:" << nl
<< " floatTransfer : " << Pstream::floatTransfer << nl
<< " nProcsSimpleSum : " << Pstream::nProcsSimpleSum << nl
<< " commsType : "
<< Pstream::commsTypeNames[Pstream::defaultCommsType]
<< endl;
}
}
jobInfo.add("root", rootPath_);
......@@ -546,7 +530,7 @@ Foam::argList::argList
sigQuit_.set();
sigSegv_.set();
if (Pstream::master())
if (Pstream::master() && bannerEnabled)
{
Info<< endl;
IOobject::writeDivider(Info);
......@@ -564,6 +548,12 @@ Foam::argList::~argList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::argList::noBanner()
{
bannerEnabled = false;
}
void Foam::argList::noParallel()
{
validOptions.erase("parallel");
......
......@@ -92,6 +92,7 @@ namespace Foam
class argList
{
// Private data
static bool bannerEnabled;
stringList args_;
HashTable<string> options_;
......@@ -213,6 +214,9 @@ public:
// Edit
//- Disable emitting the banner information
static void noBanner();
//- Remove the parallel options
static void noParallel();
......
......@@ -259,7 +259,7 @@ public:
const FieldField<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& interfaceIntCoeffs,
const lduInterfaceFieldPtrsList& interfaces,