Commit 8716061a authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: support local InfoSwitch for writeLagrangianPositions (issue #721)

- remove writeLagrangianCoordinates as InfoSwitch, since this is
  something that a regular user should not be able to disable.
parent d69c2631
......@@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "Time.H"
#include "argList.H"
#include "Pstream.H"
#include "simpleObjectRegistry.H"
#include "dimensionedConstants.H"
......@@ -42,192 +43,285 @@ void Foam::Time::readDict()
setEnv("FOAM_APPLICATION", application, false);
}
// Check for local switches and settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// - echo values, unless the application was invoked with noBanner
const bool echo = argList::bannerEnabled();
const dictionary* localDict = nullptr;
// Debug switches
if (controlDict_.found("DebugSwitches"))
// DebugSwitches
if
(
(localDict = controlDict_.subDictPtr("DebugSwitches")) != nullptr
&& localDict->size()
)
{
Info<< "Overriding DebugSwitches according to " << controlDict_.name()
<< endl;
if (echo)
{
Info<< "Overriding DebugSwitches according to "
<< controlDict_.name() << nl;
}
simpleObjectRegistry& objs = debug::debugObjects();
simpleObjectRegistry& objects = debug::debugObjects();
const dictionary& localSettings = controlDict_.subDict("DebugSwitches");
forAllConstIter(dictionary, localSettings, iter)
forAllConstIters(*localDict, iter)
{
const word& name = iter().keyword();
simpleObjectRegistryEntry* objPtr = objects.lookupPtr(name);
simpleObjectRegistryEntry* objPtr = objs.lookupPtr(name);
if (objPtr)
{
Info<< " " << iter() << endl;
const List<simpleRegIOobject*>& objects = *objPtr;
if (echo)
{
Info<< " " << iter() << nl;
}
if (iter().isDict())
{
forAll(objects, i)
for (simpleRegIOobject* obj : objects)
{
OStringStream os(IOstream::ASCII);
os << iter().dict();
IStringStream is(os.str());
objects[i]->readData(is);
obj->readData(is);
}
}
else
{
forAll(objects, i)
for (simpleRegIOobject* obj : objects)
{
objects[i]->readData(iter().stream());
obj->readData(iter().stream());
}
}
}
}
}
// Optimisation Switches
if (controlDict_.found("OptimisationSwitches"))
// InfoSwitches
if
(
(localDict = controlDict_.subDictPtr("InfoSwitches")) != nullptr
&& localDict->size()
)
{
Info<< "Overriding OptimisationSwitches according to "
<< controlDict_.name() << endl;
if (echo)
{
Info<< "Overriding InfoSwitches according to "
<< controlDict_.name() << nl;
}
simpleObjectRegistry& objects = debug::optimisationObjects();
const dictionary& localSettings = controlDict_.subDict
(
"OptimisationSwitches"
);
forAllConstIter(dictionary, localSettings, iter)
simpleObjectRegistry& objs = debug::infoObjects();
forAllConstIters(*localDict, iter)
{
const word& name = iter().keyword();
simpleObjectRegistryEntry* objPtr = objects.lookupPtr(name);
simpleObjectRegistryEntry* objPtr = objs.lookupPtr(name);
if (objPtr)
{
Info<< " " << iter() << endl;
const List<simpleRegIOobject*>& objects = *objPtr;
if (echo)
{
Info<< " " << iter() << nl;
}
if (iter().isDict())
{
forAll(objects, i)
for (simpleRegIOobject* obj : objects)
{
OStringStream os(IOstream::ASCII);
os << iter().dict();
IStringStream is(os.str());
objects[i]->readData(is);
obj->readData(is);
}
}
else
{
forAll(objects, i)
for (simpleRegIOobject* obj : objects)
{
objects[i]->readData(iter().stream());
obj->readData(iter().stream());
}
}
}
}
}
// OptimisationSwitches
if
(
(localDict = controlDict_.subDictPtr("OptimisationSwitches")) != nullptr
&& localDict->size()
)
{
if (echo)
{
Info<< "Overriding OptimisationSwitches according to "
<< controlDict_.name() << nl;
}
// Handle fileHandler override explicitly since interacts with
// local dictionary monitoring.
word fileHandlerName;
if
(
localSettings.readIfPresent("fileHandler", fileHandlerName)
&& fileHandler().type() != fileHandlerName
)
simpleObjectRegistry& objs = debug::optimisationObjects();
forAllConstIters(*localDict, iter)
{
// Remove the old watches since destroying the file
fileNameList oldWatchedFiles(controlDict_.watchIndices().size());
forAllReverse(controlDict_.watchIndices(), i)
const word& name = iter().keyword();
simpleObjectRegistryEntry* objPtr = objs.lookupPtr(name);
if (objPtr)
{
const label watchi = controlDict_.watchIndices()[i];
oldWatchedFiles[i] = fileHandler().getFile(watchi);
fileHandler().removeWatch(watchi);
}
controlDict_.watchIndices().clear();
if (echo)
{
Info<< " " << iter() << nl;
}
// Installing the new handler
Info<< "Overriding fileHandler to " << fileHandlerName << endl;
const List<simpleRegIOobject*>& objects = *objPtr;
autoPtr<fileOperation> handler
(
fileOperation::New
(
fileHandlerName,
true
)
);
Foam::fileHandler(handler);
// Reinstall old watches
fileHandler().addWatches(controlDict_, oldWatchedFiles);
if (iter().isDict())
{
for (simpleRegIOobject* obj : objects)
{
OStringStream os(IOstream::ASCII);
os << iter().dict();
IStringStream is(os.str());
obj->readData(is);
}
}
else
{
for (simpleRegIOobject* obj : objects)
{
obj->readData(iter().stream());
}
}
}
}
}
// DimensionedConstants. Handled as a special case since both e.g.
// the 'unitSet' might be changed and the individual values
if (controlDict_.found("DimensionedConstants"))
// Handle fileHandler explicitly since it affects local dictionary
// monitoring.
word fileHandlerName;
if
(
localDict
&& localDict->readIfPresent("fileHandler", fileHandlerName)
&& fileHandler().type() != fileHandlerName
)
{
Info<< "Overriding DimensionedConstants according to "
<< controlDict_.name() << endl;
if (echo)
{
Info<< "Overriding fileHandler to " << fileHandlerName << nl;
}
// Change in-memory
dimensionedConstants().merge
// Remove old watches since destroying the file
fileNameList oldWatched(controlDict_.watchIndices().size());
forAllReverse(controlDict_.watchIndices(), i)
{
const label watchi = controlDict_.watchIndices()[i];
oldWatched[i] = fileHandler().getFile(watchi);
fileHandler().removeWatch(watchi);
}
controlDict_.watchIndices().clear();
// Installing the new handler
autoPtr<fileOperation> handler
(
controlDict_.subDict("DimensionedConstants")
fileOperation::New
(
fileHandlerName,
true
)
);
Foam::fileHandler(handler);
// Reinstall old watches
fileHandler().addWatches(controlDict_, oldWatched);
}
// DimensionedConstants.
// - special case since it may change both the 'unitSet' and the
// individual values
if
(
(localDict = controlDict_.subDictPtr("DimensionedConstants")) != nullptr
&& localDict->size()
)
{
if (echo)
{
Info<< "Overriding DimensionedConstants according to "
<< controlDict_.name() << nl;
}
simpleObjectRegistry& objs = debug::dimensionedConstantObjects();
simpleObjectRegistry& objects = debug::dimensionedConstantObjects();
// Change in-memory
dimensionedConstants().merge(*localDict);
IStringStream dummyIs("");
forAllConstIter(simpleObjectRegistry, objects, iter)
forAllConstIter(simpleObjectRegistry, objs, iter)
{
const List<simpleRegIOobject*>& objects = *iter;
forAll(objects, i)
for (simpleRegIOobject* obj : objects)
{
objects[i]->readData(dummyIs);
obj->readData(dummyIs);
Info<< " ";
objects[i]->writeData(Info);
Info<< endl;
if (echo)
{
Info<< " ";
obj->writeData(Info);
Info<< nl;
}
}
}
}
// Dimension sets
if (controlDict_.found("DimensionSets"))
// DimensionSets
if
(
(localDict = controlDict_.subDictPtr("DimensionSets")) != nullptr
&& localDict->size()
)
{
Info<< "Overriding DimensionSets according to "
<< controlDict_.name() << endl;
if (echo)
{
Info<< "Overriding DimensionSets according to "
<< controlDict_.name() << nl;
}
dictionary dict(Foam::dimensionSystems());
dict.merge(controlDict_.subDict("DimensionSets"));
simpleObjectRegistry& objs = debug::dimensionSetObjects();
simpleObjectRegistry& objects = debug::dimensionSetObjects();
dictionary dict(Foam::dimensionSystems());
dict.merge(*localDict);
simpleObjectRegistryEntry* objPtr = objects.lookupPtr("DimensionSets");
simpleObjectRegistryEntry* objPtr = objs.lookupPtr("DimensionSets");
if (objPtr)
{
Info<< controlDict_.subDict("DimensionSets") << endl;
if (echo)
{
Info<< *localDict << nl;
}
const List<simpleRegIOobject*>& objects = *objPtr;
forAll(objects, i)
for (simpleRegIOobject* obj : objects)
{
OStringStream os(IOstream::ASCII);
os << dict;
IStringStream is(os.str());
objects[i]->readData(is);
obj->readData(is);
}
}
}
......
......@@ -126,6 +126,9 @@ void Foam::injectedParticle::readFields(Cloud<injectedParticle>& c)
void Foam::injectedParticle::writeFields(const Cloud<injectedParticle>& c)
{
// Force writing positions instead of coordinates
const bool oldWriteCoordinates = particle::writeLagrangianCoordinates;
const bool oldWritePositions = particle::writeLagrangianPositions;
particle::writeLagrangianCoordinates = false;
particle::writeLagrangianPositions = true;
......@@ -151,13 +154,17 @@ void Foam::injectedParticle::writeFields(const Cloud<injectedParticle>& c)
d[i] = p.d();
U[i] = p.U();
i++;
++i;
}
tag.write();
soi.write();
d.write();
U.write();
// Restore
particle::writeLagrangianCoordinates = oldWriteCoordinates;
particle::writeLagrangianPositions = oldWritePositions;
}
......@@ -168,6 +175,9 @@ void Foam::injectedParticle::writeObjects
)
{
// Force writing positions instead of coordinates
const bool oldWriteCoordinates = particle::writeLagrangianCoordinates;
const bool oldWritePositions = particle::writeLagrangianPositions;
particle::writeLagrangianCoordinates = false;
particle::writeLagrangianPositions = true;
......@@ -191,8 +201,12 @@ void Foam::injectedParticle::writeObjects
d[i] = p.d();
U[i] = p.U();
i++;
++i;
}
// Restore
particle::writeLagrangianCoordinates = oldWriteCoordinates;
particle::writeLagrangianPositions = oldWritePositions;
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -27,26 +27,33 @@ License
#include "transform.H"
#include "treeDataCell.H"
#include "cubicEqn.H"
#include "registerSwitch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::scalar Foam::particle::negativeSpaceDisplacementFactor = 1.01;
Foam::label Foam::particle::particleCount_ = 0;
namespace Foam
{
defineTypeNameAndDebug(particle, 0);
bool particle::writeLagrangianCoordinates
(
debug::infoSwitch("writeLagrangianCoordinates", 1)
);
bool particle::writeLagrangianPositions
(
debug::infoSwitch("writeLagrangianPositions", 0)
);
}
const Foam::scalar Foam::particle::negativeSpaceDisplacementFactor = 1.01;
Foam::label Foam::particle::particleCount_ = 0;
bool Foam::particle::writeLagrangianCoordinates = true;
bool Foam::particle::writeLagrangianPositions
(
Foam::debug::infoSwitch("writeLagrangianPositions", 0)
);
registerInfoSwitch
(
"writeLagrangianPositions",
bool,
Foam::particle::writeLagrangianPositions
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......
......@@ -443,8 +443,7 @@ public:
//- Destructor
virtual ~particle()
{}
virtual ~particle() = default;
// Member Functions
......
......@@ -54,10 +54,8 @@ Foam::coalCloudList::coalCloudList
setSize(cloudNames.size());
label i = 0;
forAllConstIter(wordHashSet, cloudNames, iter)
for (const word& name : cloudNames)
{
const word& name = iter.key();
Info<< "creating cloud: " << name << endl;
set
......
......@@ -2,10 +2,9 @@
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
# create mesh
runApplication blockMesh
# create ignition cells cellSet
# Create ignition cells cellSet
runApplication topoSet
runApplication $(getApplication)
......
......@@ -21,13 +21,10 @@ method scotch;
coeffs
{
n (2 2 1);
//delta 0.001; // default=0.001
//order xyz; // default=xzy
}
distributed no;
roots ( );
// ************************************************************************* //
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment