ENH: removed calcEntry

This commit is contained in:
andy
2011-02-23 16:49:26 +00:00
parent f4a84af465
commit b4dae1a5ab
9 changed files with 34 additions and 669 deletions

View File

@ -167,17 +167,6 @@ $(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C
$(functionEntries)/inputModeEntry/inputModeEntry.C
$(functionEntries)/removeEntry/removeEntry.C
/*
* Requires customized coco-cpp
* could be dropped or activated in the future
*/
/*
calcEntry = $(functionEntries)/calcEntry
$(calcEntry)/calcEntryParser.atg
$(calcEntry)/calcEntryInternal.C
$(calcEntry)/calcEntry.C
*/
IOdictionary = db/IOobjects/IOdictionary
$(IOdictionary)/IOdictionary.C
$(IOdictionary)/IOdictionaryIO.C

View File

@ -1,97 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2010 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 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/>.
\*---------------------------------------------------------------------------*/
#include "calcEntry.H"
#include "dictionary.H"
#include "addToMemberFunctionSelectionTable.H"
#include "ISstream.H"
#include "CocoParserErrors.H"
#include "calcEntryParser.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionEntries
{
defineTypeNameAndDebug(calcEntry, 0);
addToMemberFunctionSelectionTable
(
functionEntry,
calcEntry,
execute,
primitiveEntryIstream
);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::calcEntry::execute
(
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
)
{
std::istream& iss = dynamicCast<ISstream>(is).stdStream();
// define parser error handler
CocoParserErrors<calcEntryInternal::Errors>
myErrorHandler("calcEntryInternal::Parser");
calcEntryInternal::Scanner scanner(iss);
// set the starting line
scanner.Line(is.lineNumber());
calcEntryInternal::Parser parser(&scanner, &myErrorHandler);
// Attach dictionary context
parser.dict(parentDict);
parser.Parse();
// mostly have an extra newline in the lookahead token
// so subtract 1 to keep things vaguely in sync
// (this is still far from perfect)
is.lineNumber() = scanner.Line() - 1;
// a small input list to contain the answer
tokenList tokens(2);
tokens[0] = parser.Result();
tokens[1] = token::END_STATEMENT;
entry.read(parentDict, ITstream("ParserResult", tokens)());
return true;
}
// ************************************************************************* //

View File

@ -1,91 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2010 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 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/>.
Class
Foam::functionEntries::calcEntry
Description
This dictionary function entry may or may not do anything particularly
useful - depending upon what is currently being used to test.
SourceFiles
calcEntry.C
\*---------------------------------------------------------------------------*/
#ifndef calcEntry_H
#define calcEntry_H
#include "functionEntry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionEntries
{
/*---------------------------------------------------------------------------*\
Class calcEntry Declaration
\*---------------------------------------------------------------------------*/
class calcEntry
:
public functionEntry
{
// Private Member Functions
//- Disallow default bitwise copy construct
calcEntry(const calcEntry&);
//- Disallow default bitwise assignment
void operator=(const calcEntry&);
public:
//- Runtime type information
ClassName("calc");
// Member Functions
static bool execute
(
const dictionary& parentDict,
primitiveEntry& entry,
Istream& is
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionEntries
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,128 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 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/>.
\*---------------------------------------------------------------------------*/
#include "calcEntryInternal.H"
#include "addToGlobalFunctionSelectionTable.H"
#include "unitConversion.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionEntries
{
namespace calcEntryInternal
{
defineGlobalFunctionSelectionTable(dispatch,ParamList);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define globalConstant0(Name, Constant)\
scalar Name##_0(const UList<scalar>& param) \
{ \
return Constant; \
} \
addNamedToGlobalFunctionSelectionTable(dispatch,ParamList,Name##_0,&Name##_0)
#define globalFunction0(Name, Function)\
scalar Name##_0(const UList<scalar>& param) \
{ \
return Function(); \
} \
addNamedToGlobalFunctionSelectionTable(dispatch,ParamList,Name##_0,&Name##_0)
#define globalFunction1(Name, Function)\
scalar Name##_1(const UList<scalar>& param) \
{ \
return Function(param[0]); \
} \
addNamedToGlobalFunctionSelectionTable(dispatch,ParamList,Name##_1,&Name##_1)
#define globalFunction2(Name, Function)\
scalar Name##_2(const UList<scalar>& param) \
{ \
return Function(param[0], param[1]); \
} \
addNamedToGlobalFunctionSelectionTable(dispatch,ParamList,Name##_2,&Name##_2)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
globalConstant0(pi, constant::mathematical::pi);
globalFunction1(degToRad, degToRad);
globalFunction1(radToDeg, radToDeg);
globalFunction1(asin, Foam::asin);
globalFunction1(acos, Foam::acos);
globalFunction1(atan, Foam::atan);
globalFunction1(sin, Foam::sin);
globalFunction1(cos, Foam::cos);
globalFunction1(tan, Foam::tan);
globalFunction1(log, Foam::log);
globalFunction1(log10, Foam::log10);
globalFunction1(mag, Foam::mag);
globalFunction2(atan2, Foam::atan2);
globalFunction2(pow, Foam::pow);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
scalar dispatch(const word& name, const UList<scalar>& param)
{
// create lookup name with parameter count
const word lookupName = name + '_' + Foam::name(param.size());
dispatchParamListMemberFunctionTable::iterator mfIter =
dispatchParamListMemberFunctionTablePtr_->find(lookupName);
if (mfIter == dispatchParamListMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"calcEntryInternal::scalarFunctions::dispatch"
"(const word&, const UList<scalar>&) : "
) << "Unknown function " << name << nl << nl
<< "Valid types are :" << endl
<< dispatchParamListMemberFunctionTablePtr_->sortedToc()
<< exit(FatalError);
}
return mfIter()(param);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace calcEntryInternal
} // End namespace functionEntries
} // End namespace Foam
// ************************************************************************* //

View File

@ -1,80 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 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/>.
Namespace
Foam::functionEntries::calcEntryInternal
Description
Contains global functions and classes for the calcEntry.
SourceFiles
calcEntryInternal.C
\*---------------------------------------------------------------------------*/
#ifndef calcEntryInternal_H
#define calcEntryInternal_H
#include "error.H"
#include "scalar.H"
#include "DynamicList.H"
#include "globalFunctionSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionEntries
{
namespace calcEntryInternal
{
// Global Function Selectors
declareGlobalFunctionSelectionTable
(
scalar,
dispatch,
ParamList,
(
const UList<scalar>& param
),
(param)
);
//- Dispatch calculation to the named function
scalar dispatch(const word&, const UList<scalar>&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace calcEntryInternal
} // End namespace functionEntries
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,257 +0,0 @@
/*---------------------------------------------------------------------------*\
Attributed Grammar for Coco/R (-*- C++ -*- version)
compile with:
coco-cpp calcEntryParser.atg
\*---------------------------------------------------------------------------*/
[copy]
/*---------------------------------*- C++ -*---------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 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/>.
@file calcEntryParser.atg
Description
An attributed Coco/R grammar to parse simple arithmetic expressions
Includes support for dictionary $variables and some scalar functions
(eg, sin, pow, ...)
SourceFiles
generated
\*---------------------------------------------------------------------------*/
[/copy]
#include "dictionary.H"
#include "wchar.H"
#include "calcEntryInternal.H"
COMPILER calcEntry
// grammar pragmas:
$prefix=calcEntry
$namespace=Foam::functionEntries::calcEntryInternal
$define=EXPLICIT_EOF // grammar handles eof itself
$define=STREAMS_ONLY // only use STL streams
$define=NO_UTF8 // disable UTF8 on input
private:
//- The parent dictionary
dictionary* dict_;
//- The calculation result
scalar val;
//- lookup dictionary entry
scalar getDictLookup(const word&) const;
public:
//- attach a dictionary
void dict(const dictionary& dict)
{
dict_ = const_cast<dictionary*>(&dict);
}
//- Return the calculated result
scalar Result() const
{
return val;
}
/*---------------------------------------------------------------------------*/
[initialize] // add to Parser constructor
dict_ = 0;
val = 0;
[/initialize]
/*---------------------------------------------------------------------------*/
[code]
Foam::scalar Parser::getDictLookup(const word& keyword) const
{
if (!dict_)
{
FatalErrorIn
(
"calcEntry::getDictEntry(const word&) const"
) << "No dictionary attached!"
<< exit(FatalError);
return 0;
}
scalar dictValue = 0;
entry* entryPtr = dict_->lookupEntryPtr(keyword, true, false);
if (entryPtr && !entryPtr->isDict())
{
if (entryPtr->stream().size() != 1)
{
FatalErrorIn
(
"calcEntry::getDictEntry(const word&) const"
) << "keyword " << keyword << " has "
<< entryPtr->stream().size() << " values in dictionary "
<< exit(FatalError);
}
entryPtr->stream() >> dictValue;
}
else
{
FatalErrorIn
(
"calcEntry::getDictEntry(const word&) const"
) << "keyword " << keyword << " is undefined in dictionary "
<< exit(FatalError);
}
return dictValue;
}
[/code]
/*---------------------------------------------------------------------------*/
CHARACTERS
letter = 'A'..'Z' + 'a'..'z' + '_'.
digit = "0123456789".
alphanum = letter + digit.
sign = '+' + '-'.
cr = '\r'.
lf = '\n'.
tab = '\t'.
stringCh = ANY - '"' - '\\' - cr - lf.
printable = '\u0020' .. '\u007e'.
// * * * * * * * * * * * * * * * * TOKENS * * * * * * * * * * * * * * * * * //
TOKENS
// identifier
ident =
letter { alphanum }.
// string
string =
'"' { stringCh | '\\' printable } '"'.
// dictionary lookup identifier
// starts with '$' and otherwise limited to a normal identifier
variable =
'$' letter { alphanum }.
// floating point and integer numbers
number =
[sign] ('.' digit { digit } ) | ( digit { digit } [ '.' { digit } ])
[ ('E' | 'e') [sign] digit { digit } ].
// * * * * * * * * * * * PRAGMAS / COMMENTS / IGNORE * * * * * * * * * * * //
COMMENTS FROM "/*" TO "*/" NESTED
COMMENTS FROM "//" TO lf
IGNORE cr + lf + tab
// * * * * * * * * * * * * * * * PRODUCTIONS * * * * * * * * * * * * * * * //
PRODUCTIONS
calcEntry (. val = 0; .)
=
'{' Expr<val> '}' (. // reposition to immediately after the closing '}'
scanner->buffer->SetPos(t->pos + 1);
.)
| ( Expr<val> EOF )
.
/*---------------------------------------------------------------------------*/
Expr<scalar& val> (. scalar val2 = 0; .)
=
Term<val>
{
'+' Term<val2> (. val += val2; .)
| '-' Term<val2> (. val -= val2; .)
}
.
/*---------------------------------------------------------------------------*/
Term<scalar& val> (. scalar val2 = 0; .)
=
Factor<val>
{
'*' Factor<val2> (. val *= val2; .)
| '/' Factor<val2> (. val /= val2; .)
}
.
/*---------------------------------------------------------------------------*/
// Note the treatment of the leading signs is fairly generous
// eg, "10 + - 10" is treated like "10 + -10"
//
Factor<scalar& val> (. bool negative = false; .)
=
['+' | '-' (. negative = true; .)
]
(
Func<val> | '(' Expr<val> ')'
| variable (.
// skip leading '$' for the keyword
val = getDictLookup(t->toString(1, t->length()-1));
.)
| number (. val = coco_string_toDouble(t->val); .)
) (. if (negative) { val = -val; } .)
.
/*---------------------------------------------------------------------------*/
// functions like sin(x) or pow(x, y) etc.
Func<scalar& val>
=
ident (.
word funcName(t->toString());
DynamicList<scalar> stack(4);
.)
'('
[ (. scalar x; .)
Expr<x> (. stack.append(x); .)
{ ',' Expr<x> (. stack.append(x); .)
}
]
')' (. val = dispatch(funcName, stack); .)
.
/*---------------------------------------------------------------------------*/
END calcEntry.
// ************************************************************************* //

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / O peration | Version: dev.olesenm |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/

View File

@ -45,5 +45,36 @@ timePrecision 6;
runTimeModifiable true;
functions
{
systemCall1
{
type systemCall;
functionObjectLibs ("libsystemCall.so");
enabled true;
outputControl outputTime;
// called every time step
executeCalls
(
"echo execute"
);
// called at the end of the run
endCalls
(
"echo \*\*\* writing .bashrc \*\*\*"
"cat ~/.bashrc"
"echo \*\*\* done \*\*\*"
);
// called every ouput time
writeCalls
(
"echo \*\*\* writing data \*\*\*"
);
}
}
// ************************************************************************* //

View File

@ -25,8 +25,7 @@ boundaryField
{
type MarshakRadiation;
T T;
emissivityMode lookup;
emissivity uniform 1.0;
emissivity 1;
value uniform 0;
refValue uniform 0;
refGradient uniform 0;
@ -36,8 +35,7 @@ boundaryField
{
type MarshakRadiation;
T T;
emissivityMode lookup;
emissivity uniform 1.0;
emissivity 1;
value uniform 0;
refValue uniform 0;
refGradient uniform 0;