Commit 521797fa authored by mattijs's avatar mattijs
Browse files

ENH: constants: re-reading of constants

parent 94f935c8
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -26,6 +26,7 @@ License
#include "Time.H"
#include "Pstream.H"
#include "simpleObjectRegistry.H"
#include "dimensionedConstants.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -45,54 +46,42 @@ void Foam::Time::readDict()
// Debug switches
if (controlDict_.found("DebugSwitches"))
{
Info<< "Overriding DebugSwitches according to " << controlDict_.name()
<< endl;
simpleObjectRegistry& objects = debug::debugObjects();
const dictionary& localSettings = controlDict_.subDict("DebugSwitches");
forAllConstIter(dictionary, localSettings, iter)
{
const word& name = iter().keyword();
simpleObjectRegistry::iterator fnd = objects.find(name);
if (fnd != objects.end())
simpleRegIOobject* objPtr = objects.lookupPtr(name);
if (objPtr)
{
Info<< controlDict_.name() << " : overriding debug switch : "
<< iter() << endl;
Info<< " " << iter() << endl;
if (iter().isDict())
{
OStringStream os(IOstream::ASCII);
os << iter().dict();
IStringStream is(os.str());
fnd()->readData(is);
objPtr->readData(is);
}
else
{
fnd()->readData(iter().stream());
objPtr->readData(iter().stream());
}
}
}
}
// Dimension sets
if (controlDict_.found("DimensionSets"))
{
dictionary dict(Foam::dimensionSystems());
dict.merge(controlDict_.subDict("DimensionSets"));
simpleObjectRegistry& objects = debug::dimensionSetObjects();
simpleObjectRegistry::iterator fnd = objects.find("DimensionSets");
if (fnd != objects.end())
{
Info<< controlDict_.name() << " : overriding DimensionSets" << endl;
OStringStream os(IOstream::ASCII);
os << dict;
IStringStream is(os.str());
fnd()->readData(is);
}
}
// Optimisation Switches
if (controlDict_.found("OptimisationSwitches"))
{
Info<< "Overriding OptimisationSwitches according to "
<< controlDict_.name() << endl;
simpleObjectRegistry& objects = debug::optimisationObjects();
const dictionary& localSettings = controlDict_.subDict
(
......@@ -101,28 +90,192 @@ void Foam::Time::readDict()
forAllConstIter(dictionary, localSettings, iter)
{
const word& name = iter().keyword();
simpleObjectRegistry::iterator fnd = objects.find(name);
if (fnd != objects.end())
simpleRegIOobject* objPtr = objects.lookupPtr(name);
if (objPtr)
{
Info<< controlDict_.name()
<< " : overriding optimisation switch : " << iter() << endl;
Info<< " " << iter() << endl;
if (iter().isDict())
{
OStringStream os(IOstream::ASCII);
os << iter().dict();
IStringStream is(os.str());
fnd()->readData(is);
objPtr->readData(is);
}
else
{
fnd()->readData(iter().stream());
objPtr->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"))
{
Info<< "Overriding DimensionedConstants according to "
<< controlDict_.name() << endl;
// Change in-memory
dimensionedConstants().merge
(
controlDict_.subDict("DimensionedConstants")
);
simpleObjectRegistry& objects = debug::dimensionedConstantObjects();
IStringStream dummyIs("");
forAllConstIter(simpleObjectRegistry, objects, iter)
{
iter()->readData(dummyIs);
Info<< " ";
iter()->writeData(Info);
Info<< endl;
}
}
//{
// // fundamentalConstants.C
// Info<< "constant::universal::hr:"
// << Foam::constant::universal::hr
// << endl;
// Info<< "constant::universal::c:"
// << Foam::constant::universal::c
// << endl;
// Info<< "constant::universal::G:"
// << Foam::constant::universal::G
// << endl;
// Info<< "constant::universal::h:"
// << Foam::constant::universal::h
// << endl;
// Info<< "constant::electromagnetic::e:"
// << Foam::constant::electromagnetic::e
// << endl;
// Info<< "constant::atomic::me:"
// << Foam::constant::atomic::me
// << endl;
// Info<< "constant::atomic::mp:"
// << Foam::constant::atomic::mp
// << endl;
// Info<< "constant::physicoChemical::mu:"
// << Foam::constant::physicoChemical::mu
// << endl;
// Info<< "constant::physicoChemical::NA:"
// << Foam::constant::physicoChemical::NA
// << endl;
// Info<< "constant::physicoChemical::k:"
// << Foam::constant::physicoChemical::k
// << endl;
// Info<< "constant::standard::Pstd:"
// << Foam::constant::standard::Pstd
// << endl;
// Info<< "constant::standard::Tstd:"
// << Foam::constant::standard::Tstd
// << endl;
//
// // universalConstants.C
// Info<< "constant::universal::hr:"
// << Foam::constant::universal::hr
// << endl;
//
// // electromagneticConstants.C
// Info<< "constant::electromagnetic::mu0:"
// << Foam::constant::electromagnetic::mu0
// << endl;
// Info<< "constant::electromagnetic::epsilon0:"
// << Foam::constant::electromagnetic::epsilon0
// << endl;
// Info<< "constant::electromagnetic::Z0:"
// << Foam::constant::electromagnetic::Z0
// << endl;
// Info<< "constant::electromagnetic::kappa:"
// << Foam::constant::electromagnetic::kappa
// << endl;
// Info<< "constant::electromagnetic::G0:"
// << Foam::constant::electromagnetic::G0
// << endl;
// Info<< "constant::electromagnetic::KJ:"
// << Foam::constant::electromagnetic::KJ
// << endl;
// Info<< "constant::electromagnetic::RK:"
// << Foam::constant::electromagnetic::RK
// << endl;
//
//
// // atomicConstants.C
// Info<< "constant::atomic::alpha:"
// << Foam::constant::atomic::alpha
// << endl;
// Info<< "constant::atomic::Rinf:"
// << Foam::constant::atomic::Rinf
// << endl;
// Info<< "constant::atomic::a0:"
// << Foam::constant::atomic::a0
// << endl;
// Info<< "constant::physiatomic::re:"
// << Foam::constant::atomic::re
// << endl;
// Info<< "constant::atomic::Eh:"
// << Foam::constant::atomic::Eh
// << endl;
//
//
// // physicoChemicalConstants.C
// Info<< "constant::physicoChemical::R:"
// << Foam::constant::physicoChemical::R
// << endl;
// Info<< "constant::physicoChemical::F:"
// << Foam::constant::physicoChemical::F
// << endl;
// Info<< "constant::physicoChemical::sigma:"
// << Foam::constant::physicoChemical::sigma
// << endl;
// Info<< "constant::physicoChemical::b:"
// << Foam::constant::physicoChemical::b
// << endl;
// Info<< "constant::physicoChemical::c1:"
// << Foam::constant::physicoChemical::c1
// << endl;
// Info<< "constant::physicoChemical::c2:"
// << Foam::constant::physicoChemical::c2
// << endl;
//}
// Dimension sets
if (controlDict_.found("DimensionSets"))
{
Info<< "Overriding DimensionSets according to "
<< controlDict_.name() << endl;
dictionary dict(Foam::dimensionSystems());
dict.merge(controlDict_.subDict("DimensionSets"));
simpleObjectRegistry& objects = debug::dimensionSetObjects();
simpleRegIOobject* objPtr = objects.lookupPtr("DimensionSets");
if (objPtr)
{
Info<< controlDict_.subDict("DimensionSets") << endl;
OStringStream os(IOstream::ASCII);
os << dict;
IStringStream is(os.str());
objPtr->readData(is);
}
}
if (!deltaTchanged_)
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -32,100 +32,107 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
const char* const Foam::constant::atomic::group = "atomic";
namespace Foam
{
namespace constant
{
const char* const atomic::group = "atomic";
const Foam::dimensionedScalar Foam::constant::atomic::alpha
defineDimensionedConstantWithDefault
(
dimensionedConstant
atomic::group,
atomic::alpha,
dimensionedScalar
(
group,
"alpha",
dimensionedScalar
(
"alpha",
sqr(constant::electromagnetic::e)
/(
dimensionedScalar("C", dimless, 2.0)
*constant::electromagnetic::epsilon0
*constant::universal::h
*constant::universal::c
)
sqr(electromagnetic::e)
/(
dimensionedScalar("C", dimless, 2.0)
*electromagnetic::epsilon0
*universal::h
*universal::c
)
)
),
constantatomicalpha,
"alpha"
);
const Foam::dimensionedScalar Foam::constant::atomic::Rinf
defineDimensionedConstantWithDefault
(
dimensionedConstant
atomic::group,
atomic::Rinf,
dimensionedScalar
(
group,
"Rinf",
dimensionedScalar
(
"Rinf",
sqr(alpha)*me*constant::universal::c
/(dimensionedScalar("C", dimless, 2.0)*constant::universal::h)
)
)
sqr(atomic::alpha)
*atomic::me
*universal::c
/(Foam::dimensionedScalar("C", Foam::dimless, 2.0)*universal::h)
),
constantatomicRinf,
"Rinf"
);
const Foam::dimensionedScalar Foam::constant::atomic::a0
defineDimensionedConstantWithDefault
(
dimensionedConstant
atomic::group,
atomic::a0,
dimensionedScalar
(
group,
"a0",
dimensionedScalar
(
"a0",
alpha
/(
dimensionedScalar("C", dimless, 4.0*constant::mathematical::pi)
*Rinf
)
atomic::alpha
/(
Foam::dimensionedScalar("C", Foam::dimless, 4.0*mathematical::pi)
*atomic::Rinf
)
)
),
constantatomica0,
"a0"
);
const Foam::dimensionedScalar Foam::constant::atomic::re
defineDimensionedConstantWithDefault
(
dimensionedConstant
atomic::group,
atomic::re,
dimensionedScalar
(
group,
"re",
dimensionedScalar
(
"re",
sqr(constant::electromagnetic::e)
/(
dimensionedScalar("C", dimless, 4.0*constant::mathematical::pi)
*constant::electromagnetic::epsilon0
*me
*sqr(constant::universal::c)
)
Foam::sqr(electromagnetic::e)
/(
Foam::dimensionedScalar("C", Foam::dimless, 4.0*mathematical::pi)
*electromagnetic::epsilon0
*atomic::me
*Foam::sqr(universal::c)
)
)
),
constantatomicre,
"re"
);
const Foam::dimensionedScalar Foam::constant::atomic::Eh
defineDimensionedConstantWithDefault
(
dimensionedConstant
atomic::group,
atomic::Eh,
dimensionedScalar
(
group,
"Eh",
dimensionedScalar
(
"Eh",
dimensionedScalar("C", dimless, 2.0)
*Rinf*constant::universal::h*constant::universal::c
)
)
Foam::dimensionedScalar("C", Foam::dimless, 2.0)
*atomic::Rinf*universal::h*universal::c
),
constantatomicEh,
"Eh"
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace constant
} // End namespace Foam
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -28,7 +28,7 @@ License
// Constants supplied in the main controlDict
#include "fundamentalConstants.C"
// Derived constants
// Derived constants. Note:order is important
#include "universalConstants.C"
#include "electromagneticConstants.C"
#include "atomicConstants.C"
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -92,6 +92,104 @@ T dimensionedConstant
}
//- Defined dimensioned constant , lookup as \a Name
#define defineDimensionedConstant(Group,Switch,Tag,Name) \
const Foam::dimensionedScalar Switch; \
class add##Tag##ToDimensionedConstant \
: \
public Foam::simpleRegIOobject \
{ \
public: \
add##Tag##ToDimensionedConstant(const char* name) \
: \
Foam::simpleRegIOobject \
(Foam::debug::addDimensionedConstantObject,name) \
{ \
Foam::dimensionedScalar ds \
( \
Foam::dimensionedConstant \
( \
Group, \
Name \
) \
); \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
( \
Switch \
); \
s.dimensions().reset(ds.dimensions()); \
s = ds; \
} \
virtual ~add##Tag##ToDimensionedConstant() \
{} \
virtual void readData(Foam::Istream& is) \
{ \
const_cast<Foam::dimensionedScalar&>(Switch) = \
Foam::dimensionedConstant \
( \
Group, \
Name \
); \
} \
virtual void writeData(Foam::Ostream& os) const \
{ \
os << Switch; \
} \
}; \
add##Tag##ToDimensionedConstant add##Tag##ToDimensionedConstant_(Name)
//- Defined dimensioned constant with default , lookup as \a Name
#define defineDimensionedConstantWithDefault\
(Group,Switch,DefaultExpr,Tag,Name) \
const Foam::dimensionedScalar Switch; \
class add##Tag##ToDimensionedConstantWithDefault \
: \
public Foam::simpleRegIOobject \
{ \
public: \
add##Tag##ToDimensionedConstantWithDefault(const char* name) \
: \
Foam::simpleRegIOobject \
(Foam::debug::addDimensionedConstantObject,name) \
{ \
Foam::dimensionedScalar ds \
( \
Foam::dimensionedConstant \
( \
Group, \
Name, \
Foam::dimensionedScalar(Name,DefaultExpr) \
) \
); \
Foam::dimensionedScalar& s = const_cast<Foam::dimensionedScalar&> \
( \
Switch \
); \
s.dimensions().reset(ds.dimensions()); \
s = ds; \
} \
virtual ~add##Tag##ToDimensionedConstantWithDefault() \
{} \
virtual void readData(Foam::Istream& is) \
{ \
const_cast<Foam::dimensionedScalar&>(Switch) = \
Foam::dimensionedConstant \
( \
Group, \
Name, \
Foam::dimensionedScalar(Name,DefaultExpr) \
); \
} \
virtual void writeData(Foam::Ostream& os) const \
{ \
os << Switch; \
} \
}; \
add##Tag##ToDimensionedConstantWithDefault \
add##Tag##ToDimensionedConstantWithDefault_(Name)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -32,135 +32,145 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
const char* const Foam::constant::electromagnetic::group = "electromagnetic";
namespace Foam
{
namespace constant
{
const char* const electromagnetic::group = "electromagnetic";
const Foam::dimensionedScalar Foam::constant::electromagnetic::mu0
defineDimensionedConstantWithDefault
(