mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge remote branch 'OpenCFD/master' into olesenm
This commit is contained in:
@ -134,6 +134,28 @@
|
||||
+ single integer reduction instead of one reduction per monitored file.
|
||||
+ only files that can be re-read are being checked. Drastic reduction of
|
||||
number of files to check.
|
||||
*** *New* #codeStream dictionary entry method. Uses on-the-fly compilation
|
||||
of OpenFOAM C++ code to construct dictionary.
|
||||
E.g. in blockMeshDict:
|
||||
|
||||
convertToMeters 0.001;
|
||||
|
||||
vertices #codeStream
|
||||
{
|
||||
code
|
||||
#{
|
||||
label nVerts =
|
||||
readLabel(dict.lookup("nx"))
|
||||
* readLabel(dict.lookup("ny"))
|
||||
* readLabel(dict.lookup("nz"));
|
||||
pointField verts(nVerts);
|
||||
// Now fill verts here
|
||||
// ..
|
||||
os << verts;
|
||||
#};
|
||||
}
|
||||
See also doc/changes/onTheFly.txt
|
||||
|
||||
* Solvers
|
||||
A number of new solvers have been developed for a range of engineering
|
||||
applications. There has been a set of improvements to certain classes of
|
||||
@ -163,6 +185,23 @@
|
||||
+ takes optional fieldName to sample
|
||||
+ directMapped patch added 'normal' method to calculate sample points
|
||||
to e.g. sample fields just above wall (e.g. for streaklines)
|
||||
+ *New* codedFixedValue: Uses the on-the-fly code compilation from #codeStream
|
||||
to provide an in-line fixedValueFvPatchScalarField. E.g.
|
||||
|
||||
outlet
|
||||
{
|
||||
type codedFixedValue;
|
||||
value uniform 0;
|
||||
redirectType fixedValue10;
|
||||
|
||||
code
|
||||
#{
|
||||
operator==(min(10, 0.1*this->db().time().value()));
|
||||
#};
|
||||
}
|
||||
|
||||
See doc/changes/onTheFly.txt
|
||||
|
||||
* Utilities
|
||||
There have been some utilities added and updated in this release.
|
||||
*** *New* utilities
|
||||
|
||||
@ -23,16 +23,21 @@
|
||||
);
|
||||
}
|
||||
|
||||
fvScalarMatrix DrhoDtEqn
|
||||
(
|
||||
fvc::ddt(rho) + psi*correction(fvm::ddt(p))
|
||||
+ fvc::div(phi)
|
||||
==
|
||||
parcels.Srho()
|
||||
+ massSource.SuTot()
|
||||
);
|
||||
|
||||
for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
|
||||
{
|
||||
fvScalarMatrix pEqn
|
||||
(
|
||||
fvc::ddt(rho) + psi*correction(fvm::ddt(p))
|
||||
+ fvc::div(phi)
|
||||
DrhoDtEqn
|
||||
- fvm::laplacian(rho*rAU, p)
|
||||
==
|
||||
parcels.Srho()
|
||||
+ massSource.SuTot()
|
||||
);
|
||||
|
||||
pEqn.solve();
|
||||
|
||||
@ -105,7 +105,7 @@ echo $timeStamp 2>/dev/null > $packDir/.timeStamp
|
||||
if [ "$nogit" = true ]
|
||||
then
|
||||
echo "pack manually" 1>&2
|
||||
$toolsDir/foamPackSource $packDir $packFile
|
||||
foamPackSource $packDir $packFile
|
||||
else
|
||||
echo "pack with git-archive" 1>&2
|
||||
( cd $packDir && git archive --format=tar --prefix=$packDir/ HEAD) > $packBase.tar
|
||||
|
||||
@ -101,6 +101,6 @@ fi
|
||||
# add time-stamp file before packing
|
||||
echo $timeStamp 2>/dev/null > $packDir/.timeStamp
|
||||
echo "pack manually" 1>&2
|
||||
$toolsDir/foamPackSource $packDir $packFile
|
||||
foamPackSource $packDir $packFile
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
132
doc/changes/onTheFly.txt
Normal file
132
doc/changes/onTheFly.txt
Normal file
@ -0,0 +1,132 @@
|
||||
On-the-fly code compilation
|
||||
---------------------------
|
||||
|
||||
1. #codeStream
|
||||
This is a dictionary preprocessing directive ('functionEntry') which provides
|
||||
a snippet of OpenFOAM
|
||||
C++ code which gets compiled and executed to provide the actual dictionary
|
||||
entry. The snippet gets provided as three sections of C++ code which just gets
|
||||
inserted into a template:
|
||||
- 'code' section: the actual body of the code. It gets called with
|
||||
arguments
|
||||
|
||||
const dictionary& dict,
|
||||
OStream& os
|
||||
|
||||
and the C++ code can do a dict.lookup to find current dictionary values.
|
||||
|
||||
- optional 'codeInclude' section: any #include statements to include
|
||||
OpenFOAM files.
|
||||
|
||||
- optional 'codeOptions' section: any extra compilation flags to be added to
|
||||
EXE_INC in Make/options
|
||||
|
||||
To ease inputting mulit-line code there is the #{ #} syntax. Anything
|
||||
inbetween these two delimiters becomes a string with all newlines, quotes etc
|
||||
preserved.
|
||||
|
||||
Example: Look up dictionary entries and do some calculation
|
||||
|
||||
startTime 0;
|
||||
endTime 100;
|
||||
..
|
||||
writeInterval #codeStream
|
||||
{
|
||||
code
|
||||
#{
|
||||
scalar start = readScalar(dict["startTime"]);
|
||||
scalar end = readScalar(dict["endTime"]);
|
||||
label nDumps = 5;
|
||||
label interval = end-start
|
||||
os << ((start-end)/nDumps)
|
||||
#}
|
||||
};
|
||||
|
||||
|
||||
|
||||
2. Implementation
|
||||
- the #codeStream entry reads the dictionary following it, extracts the
|
||||
code, codeInclude, codeOptions sections (these are just strings) and
|
||||
calculates the SHA1 checksum of the contents.
|
||||
- it writes library source files to constant/codeStream/<sha1> and compiles it
|
||||
using 'wmake libso'.
|
||||
- the resulting library gets loaded (dlopen, dlsym) and the function
|
||||
executed
|
||||
- the function will have written its output into the Ostream which then
|
||||
gets used to construct the entry to replace the whole #codeStream section.
|
||||
- using the sha1 means that same code will only be compiled & loaded once.
|
||||
|
||||
|
||||
3. codedFixedValue
|
||||
This uses the code from codeStream to have an in-line specialised
|
||||
fixedValueFvPatchScalarField:
|
||||
|
||||
outlet
|
||||
{
|
||||
type codedFixedValue;
|
||||
value uniform 0;
|
||||
redirectType fixedValue10;
|
||||
|
||||
code
|
||||
#{
|
||||
operator==(min(10, 0.1*this->db().time().value()));
|
||||
#};
|
||||
}
|
||||
|
||||
It by default always includes fvCFD.H and adds the finiteVolume library
|
||||
to the include search path.
|
||||
|
||||
|
||||
4. Security
|
||||
Allowing the case to execute C++ code does introduce security risks.
|
||||
A thirdparty case might have a #codeStream{#code system("rm -rf .");};
|
||||
hidden somewhere in a dictionary. #codeStream is therefore not enabled by
|
||||
default - you have to enable it by setting in the system-wide controlDict
|
||||
|
||||
InfoSwitches
|
||||
{
|
||||
// Allow case-supplied c++ code (#codeStream, codedFixedValue)
|
||||
allowSystemOperations 1;
|
||||
}
|
||||
|
||||
|
||||
5. Field manipulation.
|
||||
Fields are read in as IOdictionary (*) so can be upcast to provide access
|
||||
to the mesh:
|
||||
|
||||
internalField #codeStream
|
||||
{
|
||||
codeInclude
|
||||
#{
|
||||
#include "fvCFD.H"
|
||||
#};
|
||||
|
||||
code
|
||||
#{
|
||||
const IOdictionary& d = refCast<const IOdictionary&>(dict);
|
||||
const fvMesh& mesh = refCast<const fvMesh>(d.db());
|
||||
scalarField fld(mesh.nCells(), 0.0);
|
||||
fld.writeEntry("", os);
|
||||
#};
|
||||
|
||||
codeOptions
|
||||
#{
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude
|
||||
#};
|
||||
};
|
||||
|
||||
There are unfortunately some exceptions. Following applications read
|
||||
the field as a dictionary:
|
||||
- foamFormatConvert
|
||||
- changeDictionaryDict
|
||||
- foamUpgradeCyclics
|
||||
- fieldToCell
|
||||
|
||||
Note: above construct has the problem that the boundary conditions are
|
||||
not evaluated so e.g. processor boundaries will might not hold the opposite
|
||||
cell value.
|
||||
|
||||
|
||||
6. Other
|
||||
- the implementation is still a bit raw - it compiles code overly much
|
||||
- parallel running not tested a lot. What about distributed data parallel.
|
||||
@ -868,6 +868,9 @@ InfoSwitches
|
||||
{
|
||||
writePrecision 6;
|
||||
writeJobInfo 0;
|
||||
|
||||
// Allow case-supplied c++ code (#codeStream, codedFixedValue)
|
||||
allowSystemOperations 0;
|
||||
}
|
||||
|
||||
OptimisationSwitches
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -51,6 +51,7 @@ Description
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
@ -164,6 +165,12 @@ Foam::word Foam::userName()
|
||||
}
|
||||
|
||||
|
||||
bool Foam::isAdministrator()
|
||||
{
|
||||
return (geteuid() == 0);
|
||||
}
|
||||
|
||||
|
||||
// use $HOME environment variable or passwd info
|
||||
Foam::fileName Foam::home()
|
||||
{
|
||||
@ -240,7 +247,7 @@ Foam::fileName Foam::cwd()
|
||||
|
||||
bool Foam::chDir(const fileName& dir)
|
||||
{
|
||||
return chdir(dir.c_str()) != 0;
|
||||
return chdir(dir.c_str()) == 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1065,4 +1072,31 @@ int Foam::system(const string& command)
|
||||
}
|
||||
|
||||
|
||||
void* Foam::dlOpen(const fileName& lib)
|
||||
{
|
||||
return dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::dlClose(void* handle)
|
||||
{
|
||||
return dlclose(handle) == 0;
|
||||
}
|
||||
|
||||
|
||||
void* Foam::dlSym(void* handle, const string& symbol)
|
||||
{
|
||||
void* fun = dlsym(handle, symbol.c_str());
|
||||
|
||||
char *error;
|
||||
if ((error = dlerror()) != NULL)
|
||||
{
|
||||
WarningIn("dlSym(void*, const string&)")
|
||||
<< "Cannot lookup symbol " << symbol << " : " << error
|
||||
<< endl;
|
||||
}
|
||||
return fun;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -159,6 +159,8 @@ $(dictionaryEntry)/dictionaryEntry.C
|
||||
$(dictionaryEntry)/dictionaryEntryIO.C
|
||||
|
||||
functionEntries = $(dictionary)/functionEntries
|
||||
$(functionEntries)/codeStream/codeStream.C
|
||||
$(functionEntries)/codeStream/codeStreamTools.C
|
||||
$(functionEntries)/functionEntry/functionEntry.C
|
||||
$(functionEntries)/includeEntry/includeEntry.C
|
||||
$(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -27,6 +27,7 @@ License
|
||||
#include "int.H"
|
||||
#include "token.H"
|
||||
#include <cctype>
|
||||
#include "IOstreams.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
@ -109,6 +110,27 @@ char Foam::ISstream::nextValid()
|
||||
}
|
||||
|
||||
|
||||
void Foam::ISstream::readWordToken(token& t)
|
||||
{
|
||||
word* wPtr = new word;
|
||||
|
||||
if (read(*wPtr).bad())
|
||||
{
|
||||
delete wPtr;
|
||||
t.setBad();
|
||||
}
|
||||
else if (token::compound::isCompound(*wPtr))
|
||||
{
|
||||
t = token::compound::New(*wPtr, *this).ptr();
|
||||
delete wPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = wPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::ISstream::read(token& t)
|
||||
{
|
||||
static const int maxLen = 128;
|
||||
@ -181,7 +203,44 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
||||
|
||||
return *this;
|
||||
}
|
||||
// Verbatim string
|
||||
case token::HASH :
|
||||
{
|
||||
char nextC;
|
||||
if (read(nextC).bad())
|
||||
{
|
||||
// Return hash as word
|
||||
t = token(word(c));
|
||||
return *this;
|
||||
}
|
||||
else if (nextC == token::BEGIN_BLOCK)
|
||||
{
|
||||
// Verbatim string
|
||||
string* sPtr = new string;
|
||||
|
||||
if (readVerbatim(*sPtr).bad())
|
||||
{
|
||||
delete sPtr;
|
||||
t.setBad();
|
||||
}
|
||||
else
|
||||
{
|
||||
t = sPtr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Word beginning with #
|
||||
putback(nextC);
|
||||
putback(c);
|
||||
|
||||
readWordToken(t);
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
// Number: integer or floating point
|
||||
//
|
||||
@ -302,22 +361,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
||||
default:
|
||||
{
|
||||
putback(c);
|
||||
word* wPtr = new word;
|
||||
|
||||
if (read(*wPtr).bad())
|
||||
{
|
||||
delete wPtr;
|
||||
t.setBad();
|
||||
}
|
||||
else if (token::compound::isCompound(*wPtr))
|
||||
{
|
||||
t = token::compound::New(*wPtr, *this).ptr();
|
||||
delete wPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = wPtr;
|
||||
}
|
||||
readWordToken(t);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -504,6 +548,60 @@ Foam::Istream& Foam::ISstream::read(string& str)
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::ISstream::readVerbatim(string& str)
|
||||
{
|
||||
static const int maxLen = 8000;
|
||||
static const int errLen = 80; // truncate error message for readability
|
||||
static char buf[maxLen];
|
||||
|
||||
char c;
|
||||
|
||||
register int nChar = 0;
|
||||
|
||||
while (get(c))
|
||||
{
|
||||
if (c == token::HASH)
|
||||
{
|
||||
char nextC;
|
||||
get(nextC);
|
||||
if (nextC == token::END_BLOCK)
|
||||
{
|
||||
buf[nChar] = '\0';
|
||||
str = buf;
|
||||
return *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
putback(nextC);
|
||||
}
|
||||
}
|
||||
|
||||
buf[nChar++] = c;
|
||||
if (nChar == maxLen)
|
||||
{
|
||||
buf[errLen] = '\0';
|
||||
|
||||
FatalIOErrorIn("ISstream::readVerbatim(string&)", *this)
|
||||
<< "string \"" << buf << "...\"\n"
|
||||
<< " is too long (max. " << maxLen << " characters)"
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// don't worry about a dangling backslash if string terminated prematurely
|
||||
buf[errLen] = buf[nChar] = '\0';
|
||||
|
||||
FatalIOErrorIn("ISstream::readVerbatim(string&)", *this)
|
||||
<< "problem while reading string \"" << buf << "...\""
|
||||
<< exit(FatalIOError);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Istream& Foam::ISstream::read(label& val)
|
||||
{
|
||||
is_ >> val;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -64,9 +64,15 @@ class ISstream
|
||||
|
||||
char nextValid();
|
||||
|
||||
void readWordToken(token&);
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
|
||||
//- Read a verbatim string (excluding block delimiters).
|
||||
Istream& readVerbatim(string&);
|
||||
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const ISstream&);
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -104,6 +104,7 @@ public:
|
||||
END_BLOCK = '}',
|
||||
COLON = ':',
|
||||
COMMA = ',',
|
||||
HASH = '#',
|
||||
|
||||
BEGIN_STRING = '"',
|
||||
END_STRING = BEGIN_STRING,
|
||||
|
||||
@ -0,0 +1,245 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 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 "codeStream.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
#include "IStringStream.H"
|
||||
#include "OStringStream.H"
|
||||
#include "IOstreams.H"
|
||||
#include "SHA1Digest.H"
|
||||
#include "OSHA1stream.H"
|
||||
#include "codeStreamTools.H"
|
||||
#include "dlLibraryTable.H"
|
||||
#include "OSspecific.H"
|
||||
#include "Time.H"
|
||||
#include "Pstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionEntries
|
||||
{
|
||||
defineTypeNameAndDebug(codeStream, 0);
|
||||
|
||||
addToMemberFunctionSelectionTable
|
||||
(
|
||||
functionEntry,
|
||||
codeStream,
|
||||
execute,
|
||||
primitiveEntryIstream
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionEntries::codeStream::execute
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
primitiveEntry& entry,
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
if (isAdministrator())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "This code should not be executed by someone with administrator"
|
||||
<< " rights due to security reasons." << endl
|
||||
<< "(it writes a shared library which then gets loaded "
|
||||
<< "using dlopen)"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
|
||||
// Read three sections of code. Remove any leading empty lines
|
||||
// (necessary for compilation options, just visually pleasing for includes
|
||||
// and body).
|
||||
dictionary codeDict(is);
|
||||
|
||||
string codeInclude = "";
|
||||
if (codeDict.found("codeInclude"))
|
||||
{
|
||||
codeInclude = codeStreamTools::stripLeading(codeDict["codeInclude"]);
|
||||
}
|
||||
string code = codeStreamTools::stripLeading(codeDict["code"]);
|
||||
|
||||
string codeOptions = "";
|
||||
if (codeDict.found("codeOptions"))
|
||||
{
|
||||
codeOptions = codeStreamTools::stripLeading(codeDict["codeOptions"]);
|
||||
}
|
||||
|
||||
|
||||
// Create name out of contents
|
||||
|
||||
SHA1Digest sha;
|
||||
{
|
||||
OSHA1stream os;
|
||||
os << codeInclude << code << codeOptions;
|
||||
sha = os.digest();
|
||||
}
|
||||
fileName name;
|
||||
{
|
||||
OStringStream str;
|
||||
str << sha;
|
||||
name = "codeStream" + str.str();
|
||||
}
|
||||
|
||||
fileName dir;
|
||||
if (isA<IOdictionary>(parentDict))
|
||||
{
|
||||
const IOdictionary& d = static_cast<const IOdictionary&>(parentDict);
|
||||
dir = d.db().time().constantPath()/"codeStream"/name;
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = "codeStream"/name;
|
||||
}
|
||||
|
||||
|
||||
fileName libPath
|
||||
(
|
||||
Foam::getEnv("FOAM_USER_LIBBIN")
|
||||
/ "lib"
|
||||
+ name
|
||||
+ ".so"
|
||||
);
|
||||
|
||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||
|
||||
if (!lib)
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
if (!codeStreamTools::upToDate(dir, sha))
|
||||
{
|
||||
Info<< "Creating new library in " << libPath << endl;
|
||||
|
||||
fileName templates(Foam::getEnv("OTF_TEMPLATE_DIR"));
|
||||
if (!templates.size())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Please set environment variable OTF_TEMPLATE_DIR"
|
||||
<< " to point to the location of codeStreamTemplate.C"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
List<fileAndVars> copyFiles(1);
|
||||
copyFiles[0].first() = templates/"codeStreamTemplate.C";
|
||||
stringPairList bodyVars(2);
|
||||
bodyVars[0] = Pair<string>("OTF_INCLUDES", codeInclude);
|
||||
bodyVars[1] = Pair<string>("OTF_BODY", code);
|
||||
copyFiles[0].second() = bodyVars;
|
||||
|
||||
List<fileAndContent> filesContents(2);
|
||||
// Write Make/files
|
||||
filesContents[0].first() = "Make/files";
|
||||
filesContents[0].second() =
|
||||
"codeStreamTemplate.C \n\
|
||||
LIB = $(FOAM_USER_LIBBIN)/lib" + name;
|
||||
// Write Make/options
|
||||
filesContents[1].first() = "Make/options";
|
||||
filesContents[1].second() =
|
||||
"EXE_INC = -g\\\n" + codeOptions + "\n\nLIB_LIBS = ";
|
||||
|
||||
codeStreamTools writer(name, copyFiles, filesContents);
|
||||
if (!writer.copyFilesContents(dir))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Failed writing " << endl
|
||||
<< copyFiles << endl
|
||||
<< filesContents
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
Foam::string wmakeCmd("wmake libso " + dir);
|
||||
Info<< "Invoking " << wmakeCmd << endl;
|
||||
if (Foam::system(wmakeCmd))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Failed " << wmakeCmd << exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dlLibraryTable::open(libPath))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Failed loading library " << libPath << exit(FatalIOError);
|
||||
}
|
||||
|
||||
lib = dlLibraryTable::findLibrary(libPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "Reusing library in " << libPath << endl;
|
||||
}
|
||||
|
||||
|
||||
// Find the library handle.
|
||||
void (*function)(const dictionary&, Ostream&);
|
||||
function = reinterpret_cast<void(*)(const dictionary&, Ostream&)>
|
||||
(
|
||||
dlSym(lib, name)
|
||||
);
|
||||
|
||||
if (!function)
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"functionEntries::codeStream::execute(..)",
|
||||
parentDict
|
||||
) << "Failed looking up symbol " << name
|
||||
<< " in library " << lib << exit(FatalIOError);
|
||||
}
|
||||
|
||||
OStringStream os;
|
||||
(*function)(parentDict, os);
|
||||
IStringStream resultStream(os.str());
|
||||
entry.read(parentDict, resultStream);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,136 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 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::codeStream
|
||||
|
||||
Description
|
||||
Dictionary entry that contains C++ OpenFOAM code that is compiled to
|
||||
generate the entry itself. So
|
||||
- codeStream reads three entries: 'code', 'codeInclude' (optional),
|
||||
'codeOptions' (optional)
|
||||
and uses those to generate library sources inside constant/codeStream/
|
||||
- these get compiled using 'wmake libso'
|
||||
- the resulting library is loaded in executed with as arguments
|
||||
const dictionary& dict,
|
||||
Ostream& os
|
||||
where the dictionary is the current dictionary.
|
||||
- the code has to write into Ostream which is then used to construct
|
||||
the actual dictionary entry.
|
||||
|
||||
|
||||
E.g. to set the internal field of a field:
|
||||
|
||||
internalField #codeStream
|
||||
{
|
||||
code
|
||||
#{
|
||||
const IOdictionary& d = static_cast<const IOdictionary&>(dict);
|
||||
const fvMesh& mesh = refCast<const fvMesh>(d.db());
|
||||
scalarField fld(mesh.nCells(), 12.34);
|
||||
fld.writeEntry("", os);
|
||||
#};
|
||||
|
||||
//- Optional:
|
||||
codeInclude
|
||||
#{
|
||||
#include "fvCFD.H"
|
||||
#};
|
||||
codeOptions
|
||||
#{
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude
|
||||
#};
|
||||
};
|
||||
|
||||
|
||||
Note the #{ #} syntax which is just a way of inputting strings with embedded
|
||||
newlines.
|
||||
|
||||
Limitations:
|
||||
- '~' symbol not allowed inside the code sections.
|
||||
- probably some other limitations (uses string::expand which expands $, ~)
|
||||
|
||||
SourceFiles
|
||||
codeStream.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef codeStream_H
|
||||
#define codeStream_H
|
||||
|
||||
#include "functionEntry.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
class ISstream;
|
||||
|
||||
namespace functionEntries
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class codeStream Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class codeStream
|
||||
:
|
||||
public functionEntry
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
codeStream(const codeStream&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const codeStream&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
ClassName("codeStream");
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
static bool execute
|
||||
(
|
||||
const dictionary& parentDict,
|
||||
primitiveEntry& entry,
|
||||
Istream& is
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionEntries
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,282 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 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
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "codeStreamTools.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "OSspecific.H"
|
||||
#include "dictionary.H"
|
||||
#include "dlLibraryTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
int Foam::codeStreamTools::allowSystemOperations
|
||||
(
|
||||
Foam::debug::infoSwitch("allowSystemOperations", 0)
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::codeStreamTools::copyAndExpand
|
||||
(
|
||||
ISstream& sourceStr,
|
||||
OSstream& destStr
|
||||
) const
|
||||
{
|
||||
if (!sourceStr.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"codeStreamTools::copyAndExpand()"
|
||||
" const"
|
||||
) << "Failed opening for reading " << sourceStr.name()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (!destStr.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"codeStreamTools::copyAndExpand()"
|
||||
" const"
|
||||
) << "Failed writing " << destStr.name() << exit(FatalError);
|
||||
}
|
||||
|
||||
// Copy file whilst rewriting environment vars
|
||||
string line;
|
||||
do
|
||||
{
|
||||
sourceStr.getLine(line);
|
||||
line.expand(true, true); // replace any envvars inside substitutions
|
||||
destStr<< line.c_str() << nl;
|
||||
}
|
||||
while (sourceStr.good());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::codeStreamTools::codeStreamTools()
|
||||
{}
|
||||
|
||||
|
||||
Foam::codeStreamTools::codeStreamTools
|
||||
(
|
||||
const word& name,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
name_(name)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
Foam::codeStreamTools::codeStreamTools
|
||||
(
|
||||
const word& name,
|
||||
const List<fileAndVars>& copyFiles,
|
||||
const List<fileAndContent>& filesContents
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
copyFiles_(copyFiles),
|
||||
filesContents_(filesContents)
|
||||
{}
|
||||
|
||||
|
||||
Foam::codeStreamTools::codeStreamTools(const codeStreamTools& otf)
|
||||
:
|
||||
name_(otf.name_),
|
||||
copyFiles_(otf.copyFiles_),
|
||||
filesContents_(otf.filesContents_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const
|
||||
{
|
||||
if (!allowSystemOperations)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"codeStreamTools::copyFilesContents(const fileName&) const"
|
||||
) << "Loading a shared library using case-supplied code is not"
|
||||
<< " enabled by default" << endl
|
||||
<< "because of security issues. If you trust the code you can"
|
||||
<< " enable this" << endl
|
||||
<< "facility be adding to the InfoSwitches setting in the system"
|
||||
<< " controlDict" << endl
|
||||
<< endl
|
||||
<< " allowSystemOperations 1" << endl
|
||||
<< endl
|
||||
<< "The system controlDict is either" << endl
|
||||
<< endl
|
||||
<< " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << endl
|
||||
<< endl
|
||||
<< "or" << endl
|
||||
<< endl
|
||||
<< " $WM_PROJECT_DIR/etc/controlDict" << endl
|
||||
<< endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Create dir
|
||||
mkDir(dir);
|
||||
|
||||
//Info<< "Setting envvar OTF_TYPENAME=" << name_ << endl;
|
||||
setEnv("OTF_TYPENAME", name_, true);
|
||||
// Copy any template files
|
||||
forAll(copyFiles_, i)
|
||||
{
|
||||
const List<Pair<string> >& rules = copyFiles_[i].second();
|
||||
forAll(rules, j)
|
||||
{
|
||||
//Info<< "Setting envvar " << rules[j].first() << endl;
|
||||
setEnv(rules[j].first(), rules[j].second(), true);
|
||||
}
|
||||
|
||||
const fileName sourceFile = fileName(copyFiles_[i].first()).expand();
|
||||
const fileName destFile = dir/sourceFile.name();
|
||||
|
||||
IFstream sourceStr(sourceFile);
|
||||
//Info<< "Reading from " << sourceStr.name() << endl;
|
||||
if (!sourceStr.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"codeStreamTools::copyFilesContents()"
|
||||
" const"
|
||||
) << "Failed opening " << sourceFile << exit(FatalError);
|
||||
}
|
||||
|
||||
OFstream destStr(destFile);
|
||||
//Info<< "Writing to " << destFile.name() << endl;
|
||||
if (!destStr.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"codeStreamTools::copyFilesContents()"
|
||||
" const"
|
||||
) << "Failed writing " << destFile << exit(FatalError);
|
||||
}
|
||||
|
||||
copyAndExpand(sourceStr, destStr);
|
||||
}
|
||||
|
||||
// Files that are always written:
|
||||
forAll(filesContents_, i)
|
||||
{
|
||||
fileName f = fileName(dir/filesContents_[i].first()).expand();
|
||||
|
||||
mkDir(f.path());
|
||||
OFstream str(f);
|
||||
//Info<< "Writing to " << filesContents_[i].first() << endl;
|
||||
if (!str.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"codeStreamTools::copyFilesContents()"
|
||||
" const"
|
||||
) << "Failed writing " << f << exit(FatalError);
|
||||
}
|
||||
str << filesContents_[i].second().c_str() << endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::codeStreamTools::stripLeading(const string& s)
|
||||
{
|
||||
label sz = s.size();
|
||||
if (sz > 0 && s[0] == '\n')
|
||||
{
|
||||
return s(1, sz-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::codeStreamTools::writeDigest
|
||||
(
|
||||
const fileName& dir,
|
||||
const SHA1Digest& sha1
|
||||
)
|
||||
{
|
||||
OFstream str(dir/"SHA1Digest");
|
||||
str << sha1;
|
||||
return str.good();
|
||||
}
|
||||
|
||||
|
||||
Foam::SHA1Digest Foam::codeStreamTools::readDigest(const fileName& dir)
|
||||
{
|
||||
IFstream str(dir/"SHA1Digest");
|
||||
return SHA1Digest(str);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::codeStreamTools::upToDate
|
||||
(
|
||||
const fileName& dir,
|
||||
const SHA1Digest& sha1
|
||||
)
|
||||
{
|
||||
if (!exists(dir/"SHA1Digest") || readDigest(dir) != sha1)
|
||||
{
|
||||
writeDigest(dir, sha1);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::codeStreamTools::read(const dictionary& dict)
|
||||
{
|
||||
dict.lookup("copyFiles") >> copyFiles_;
|
||||
dict.lookup("filesContents") >> filesContents_;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::codeStreamTools::writeDict(Ostream& os) const
|
||||
{
|
||||
os.writeKeyword("copyFiles") << copyFiles_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("filesContents") << filesContents_ << token::END_STATEMENT
|
||||
<< nl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,144 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 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
|
||||
|
||||
Class
|
||||
Foam::codeStreamTools
|
||||
|
||||
Description
|
||||
Base for all things on-the-fly from dictionary
|
||||
|
||||
SourceFiles
|
||||
codeStreamTools.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef codeStreamTools_H
|
||||
#define codeStreamTools_H
|
||||
|
||||
#include "Tuple2.H"
|
||||
#include "Pair.H"
|
||||
#include "SHA1Digest.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
|
||||
typedef List<Pair<string> > stringPairList;
|
||||
typedef Tuple2<fileName, List<Pair<string> > > fileAndVars;
|
||||
typedef Tuple2<fileName, string> fileAndContent;
|
||||
|
||||
|
||||
class OSstream;
|
||||
class ISstream;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class codeStreamTools Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class codeStreamTools
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name for underlying set
|
||||
word name_;
|
||||
|
||||
//- Files to copy
|
||||
List<fileAndVars> copyFiles_;
|
||||
|
||||
//- Direct contents for files
|
||||
List<fileAndContent> filesContents_;
|
||||
|
||||
protected:
|
||||
|
||||
void copyAndExpand(ISstream&, OSstream&) const;
|
||||
|
||||
public:
|
||||
|
||||
static int allowSystemOperations;
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
codeStreamTools();
|
||||
|
||||
//- Construct from dictionary
|
||||
codeStreamTools(const word& name, const dictionary& dict);
|
||||
|
||||
//- Copy from components
|
||||
codeStreamTools
|
||||
(
|
||||
const word& name,
|
||||
const List<fileAndVars>&,
|
||||
const List<fileAndContent>&
|
||||
);
|
||||
|
||||
//- Construct copy
|
||||
codeStreamTools(const codeStreamTools& otf);
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
const List<Tuple2<fileName, List<Pair<string> > > >& copyFiles() const
|
||||
{
|
||||
return copyFiles_;
|
||||
}
|
||||
|
||||
const List<Tuple2<fileName, string> >& filesContents() const
|
||||
{
|
||||
return filesContents_;
|
||||
}
|
||||
|
||||
const word& name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
bool copyFilesContents(const fileName& dir) const;
|
||||
|
||||
static void* findLibrary(const fileName& libPath);
|
||||
|
||||
static string stripLeading(const string&);
|
||||
|
||||
static bool writeDigest(const fileName& dir, const SHA1Digest& sha1);
|
||||
static SHA1Digest readDigest(const fileName& dir);
|
||||
static bool upToDate(const fileName& dir, const SHA1Digest& sha1);
|
||||
|
||||
bool read(const dictionary&);
|
||||
|
||||
void writeDict(Ostream&) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -24,8 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "dlLibraryTable.H"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include "OSspecific.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -56,7 +55,7 @@ Foam::dlLibraryTable::~dlLibraryTable()
|
||||
{
|
||||
forAllConstIter(dlLibraryTable, *this, iter)
|
||||
{
|
||||
dlclose(iter.key());
|
||||
dlClose(iter.key());
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,15 +66,14 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName)
|
||||
{
|
||||
if (functionLibName.size())
|
||||
{
|
||||
void* functionLibPtr =
|
||||
dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
|
||||
void* functionLibPtr = dlOpen(functionLibName);
|
||||
|
||||
if (!functionLibPtr)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"dlLibraryTable::open(const fileName& functionLibName)"
|
||||
) << "could not load " << dlerror()
|
||||
) << "could not load " << functionLibName
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
@ -99,6 +97,43 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName)
|
||||
}
|
||||
|
||||
|
||||
bool Foam::dlLibraryTable::close(const fileName& functionLibName)
|
||||
{
|
||||
void* libPtr = findLibrary(functionLibName);
|
||||
if (libPtr)
|
||||
{
|
||||
loadedLibraries.erase(libPtr);
|
||||
|
||||
if (!dlClose(libPtr))
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"dlLibraryTable::close(const fileName& functionLibName)"
|
||||
) << "could not close " << functionLibName
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
|
||||
{
|
||||
forAllConstIter(dlLibraryTable, loadedLibraries, iter)
|
||||
{
|
||||
if (iter() == functionLibName)
|
||||
{
|
||||
return iter.key();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::dlLibraryTable::open
|
||||
(
|
||||
const dictionary& dict,
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -97,6 +97,12 @@ public:
|
||||
//- Open the named library
|
||||
static bool open(const fileName& name);
|
||||
|
||||
//- Close the named library
|
||||
static bool close(const fileName& name);
|
||||
|
||||
//- Find the handle of the named library
|
||||
static void* findLibrary(const fileName& name);
|
||||
|
||||
//- Open all the libraries listed in the 'libsEntry' entry in the
|
||||
// given dictionary if present
|
||||
static bool open(const dictionary&, const word& libsEntry);
|
||||
|
||||
@ -77,6 +77,9 @@ word domainName();
|
||||
//- Return the user's login name
|
||||
word userName();
|
||||
|
||||
//- Is user administrator
|
||||
bool isAdministrator();
|
||||
|
||||
//- Return home directory path name for the current user
|
||||
fileName home();
|
||||
|
||||
@ -181,6 +184,16 @@ bool ping(const word&, const label timeOut=10);
|
||||
//- Execute the specified command
|
||||
int system(const string& command);
|
||||
|
||||
//- open a shared library. Return handle to library
|
||||
void* dlOpen(const fileName& lib);
|
||||
|
||||
//- Close a dlopened library using handle. Return true if successful
|
||||
bool dlClose(void*);
|
||||
|
||||
//- Lookup a symbol in a dlopened library using handle
|
||||
void* dlSym(void* handle, const string& symbol);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -94,7 +94,7 @@ Foam::string& Foam::string::replaceAll
|
||||
|
||||
|
||||
// Expand all occurences of environment variables and initial tilde sequences
|
||||
Foam::string& Foam::string::expand(const bool recurse)
|
||||
Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
|
||||
{
|
||||
size_type startEnvar = 0;
|
||||
|
||||
@ -142,7 +142,7 @@ Foam::string& Foam::string::expand(const bool recurse)
|
||||
{
|
||||
if (recurse)
|
||||
{
|
||||
enVarString.expand();
|
||||
enVarString.expand(recurse, allowEmptyVar);
|
||||
}
|
||||
std::string::replace
|
||||
(
|
||||
@ -152,11 +152,18 @@ Foam::string& Foam::string::expand(const bool recurse)
|
||||
);
|
||||
startEnvar += enVarString.size();
|
||||
}
|
||||
else if (allowEmptyVar)
|
||||
{
|
||||
std::string::replace
|
||||
(
|
||||
startEnvar,
|
||||
endEnvar - startEnvar + 1,
|
||||
""
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//startEnvar = endEnvar;
|
||||
|
||||
FatalErrorIn("string::expand()")
|
||||
FatalErrorIn("string::expand(const bool, const bool)")
|
||||
<< "Unknown variable name " << enVar << '.'
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
@ -182,7 +182,11 @@ public:
|
||||
//
|
||||
// \sa
|
||||
// Foam::findEtcFile
|
||||
string& expand(const bool recurse=false);
|
||||
string& expand
|
||||
(
|
||||
const bool recurse=false,
|
||||
const bool allowEmptyVar = false
|
||||
);
|
||||
|
||||
//- Remove repeated characters returning true if string changed
|
||||
bool removeRepeated(const char);
|
||||
|
||||
@ -114,6 +114,8 @@ derivedFvPatchFields = $(fvPatchFields)/derived
|
||||
$(derivedFvPatchFields)/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
|
||||
$(derivedFvPatchFields)/advective/advectiveFvPatchFields.C
|
||||
|
||||
$(derivedFvPatchFields)/codedFixedValue/codedFixedValueFvPatchScalarField.C
|
||||
$(derivedFvPatchFields)/codedFixedValue/codeProperties.C
|
||||
$(derivedFvPatchFields)/directMappedFixedValue/directMappedFixedValueFvPatchFields.C
|
||||
$(derivedFvPatchFields)/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C
|
||||
$(derivedFvPatchFields)/fan/fanFvPatchFields.C
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 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 "codeProperties.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
defineTypeNameAndDebug(Foam::codeProperties, 0);
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::codeProperties::codeProperties(const IOobject& io)
|
||||
:
|
||||
IOdictionary(io),
|
||||
modified_(true)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::codeProperties::read()
|
||||
{
|
||||
if (regIOobject::read())
|
||||
{
|
||||
modified_ = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,96 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 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::codeProperties
|
||||
|
||||
Description
|
||||
IOdictionary + flag whether file has changed.
|
||||
|
||||
SourceFiles
|
||||
codeProperties.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef codeProperties_H
|
||||
#define codeProperties_H
|
||||
|
||||
#include "MeshObject.H"
|
||||
#include "IOdictionary.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class codeProperties Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class codeProperties
|
||||
:
|
||||
public IOdictionary
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- File change
|
||||
mutable bool modified_;
|
||||
|
||||
public:
|
||||
|
||||
// Declare name of the class and its debug switch
|
||||
ClassName("codeDict");
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from IOobject
|
||||
codeProperties(const IOobject&);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
bool modified() const
|
||||
{
|
||||
return modified_;
|
||||
}
|
||||
|
||||
void setUnmodified() const
|
||||
{
|
||||
modified_ = false;
|
||||
}
|
||||
|
||||
//- Read the solution dictionary
|
||||
virtual bool read();
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,419 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2011 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
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "codedFixedValueFvPatchScalarField.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvPatchFieldMapper.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "volFields.H"
|
||||
#include "dlLibraryTable.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "codeStreamTools.H"
|
||||
#include "codeProperties.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
const Foam::codeProperties&
|
||||
Foam::codedFixedValueFvPatchScalarField::dict() const
|
||||
{
|
||||
if (db().foundObject<codeProperties>(codeProperties::typeName))
|
||||
{
|
||||
return db().lookupObject<codeProperties>
|
||||
(
|
||||
codeProperties::typeName
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
codeProperties* props = new codeProperties
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
codeProperties::typeName,
|
||||
db().time().system(),
|
||||
db(),
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
)
|
||||
);
|
||||
|
||||
return db().store(props);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::codedFixedValueFvPatchScalarField::writeLibrary
|
||||
(
|
||||
const fileName dir,
|
||||
const fileName libPath,
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
Info<< "Creating new library in " << libPath << endl;
|
||||
|
||||
// Write files for new library
|
||||
if (Pstream::master())
|
||||
{
|
||||
fileName templates(Foam::getEnv("OTF_TEMPLATE_DIR"));
|
||||
if (!templates.size())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
||||
dict
|
||||
) << "Please set environment variable OTF_TEMPLATE_DIR"
|
||||
<< " to point to the location of "
|
||||
<< "fixedValueFvPatchScalarFieldTemplate.C"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
|
||||
// Extract sections of code
|
||||
string codeInclude = "";
|
||||
if (dict.found("codeInclude"))
|
||||
{
|
||||
codeInclude = codeStreamTools::stripLeading(dict["codeInclude"]);
|
||||
}
|
||||
string code = codeStreamTools::stripLeading(dict["code"]);
|
||||
|
||||
string codeOptions = "";
|
||||
if (dict.found("codeOptions"))
|
||||
{
|
||||
codeOptions = codeStreamTools::stripLeading(dict["codeOptions"]);
|
||||
}
|
||||
|
||||
|
||||
List<fileAndVars> copyFiles(2);
|
||||
copyFiles[0].first() =
|
||||
templates/"fixedValueFvPatchScalarFieldTemplate.C";
|
||||
|
||||
copyFiles[0].second().setSize(2);
|
||||
copyFiles[0].second()[0] = Pair<string>("OTF_INCLUDES", codeInclude);
|
||||
copyFiles[0].second()[1] = Pair<string>("OTF_UPDATECOEFFS", code);
|
||||
|
||||
copyFiles[1].first() =
|
||||
templates/"fixedValueFvPatchScalarFieldTemplate.H";
|
||||
|
||||
|
||||
|
||||
List<fileAndContent> filesContents(2);
|
||||
// Write Make/files
|
||||
filesContents[0].first() = "Make/files";
|
||||
filesContents[0].second() =
|
||||
"fixedValueFvPatchScalarFieldTemplate.C \n\n"
|
||||
"LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_;
|
||||
// Write Make/options
|
||||
filesContents[1].first() = "Make/options";
|
||||
filesContents[1].second() =
|
||||
"EXE_INC = -g\\\n -I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
|
||||
+ codeOptions
|
||||
+ "\n\nLIB_LIBS = ";
|
||||
|
||||
codeStreamTools writer(redirectType_, copyFiles, filesContents);
|
||||
if (!writer.copyFilesContents(dir))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
|
||||
dict
|
||||
) << "Failed writing " << endl
|
||||
<< copyFiles << endl
|
||||
<< filesContents
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
|
||||
{
|
||||
if (isAdministrator())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::updateLibrary()",
|
||||
dict_
|
||||
) << "This code should not be executed by someone with administrator"
|
||||
<< " rights due to security reasons." << endl
|
||||
<< "(it writes a shared library which then gets loaded "
|
||||
<< "using dlopen)"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
const fileName dir =
|
||||
db().time().constantPath()/"codeStream"/redirectType_;
|
||||
//Info<< "dir:" << dir << endl;
|
||||
|
||||
const fileName libPath
|
||||
(
|
||||
Foam::getEnv("FOAM_USER_LIBBIN")
|
||||
/ "lib"
|
||||
+ redirectType_
|
||||
+ ".so"
|
||||
);
|
||||
//Info<< "libPath:" << libPath << endl;
|
||||
|
||||
void* lib = dlLibraryTable::findLibrary(libPath);
|
||||
|
||||
if (dict_.found("code"))
|
||||
{
|
||||
if (!lib)
|
||||
{
|
||||
writeLibrary(dir, libPath, dict_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const codeProperties& onTheFlyDict = dict();
|
||||
|
||||
if (onTheFlyDict.modified())
|
||||
{
|
||||
onTheFlyDict.setUnmodified();
|
||||
|
||||
// Remove instantiation of fvPatchField provided by library
|
||||
redirectPatchFieldPtr_.clear();
|
||||
// Unload library
|
||||
if (lib)
|
||||
{
|
||||
if (!dlLibraryTable::close(libPath))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::updateLibrary(..)",
|
||||
onTheFlyDict
|
||||
) << "Failed unloading library " << libPath
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
lib = NULL;
|
||||
}
|
||||
|
||||
const dictionary& codeDict = onTheFlyDict.subDict(redirectType_);
|
||||
writeLibrary(dir, libPath, codeDict);
|
||||
}
|
||||
}
|
||||
|
||||
if (!lib)
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
Foam::string wmakeCmd("wmake libso " + dir);
|
||||
Info<< "Invoking " << wmakeCmd << endl;
|
||||
if (Foam::system(wmakeCmd))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::updateLibrary()",
|
||||
dict_
|
||||
) << "Failed " << wmakeCmd << exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
bool dummy = true;
|
||||
reduce(dummy, orOp<bool>());
|
||||
|
||||
if (!dlLibraryTable::open(libPath))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"codedFixedValueFvPatchScalarField::updateLibrary()",
|
||||
dict_
|
||||
) << "Failed loading library " << libPath << exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::codedFixedValueFvPatchScalarField::
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
)
|
||||
:
|
||||
fixedValueFvPatchField<scalar>(p, iF),
|
||||
redirectPatchFieldPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
Foam::codedFixedValueFvPatchScalarField::
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const codedFixedValueFvPatchScalarField& ptf,
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF,
|
||||
const fvPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
fixedValueFvPatchField<scalar>(ptf, p, iF, mapper),
|
||||
dict_(ptf.dict_),
|
||||
redirectType_(ptf.redirectType_),
|
||||
redirectPatchFieldPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
Foam::codedFixedValueFvPatchScalarField::
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fixedValueFvPatchField<scalar>(p, iF, dict),
|
||||
dict_(dict),
|
||||
redirectType_(dict.lookup("redirectType")),
|
||||
redirectPatchFieldPtr_(NULL)
|
||||
{
|
||||
updateLibrary();
|
||||
}
|
||||
|
||||
|
||||
Foam::codedFixedValueFvPatchScalarField::
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const codedFixedValueFvPatchScalarField& ptf
|
||||
)
|
||||
:
|
||||
fixedValueFvPatchField<scalar>(ptf),
|
||||
dict_(ptf.dict_),
|
||||
redirectType_(ptf.redirectType_),
|
||||
redirectPatchFieldPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
Foam::codedFixedValueFvPatchScalarField::
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const codedFixedValueFvPatchScalarField& ptf,
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
)
|
||||
:
|
||||
fixedValueFvPatchField<scalar>(ptf, iF),
|
||||
dict_(ptf.dict_),
|
||||
redirectType_(ptf.redirectType_),
|
||||
redirectPatchFieldPtr_(NULL)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::fvPatchScalarField&
|
||||
Foam::codedFixedValueFvPatchScalarField::redirectPatchField() const
|
||||
{
|
||||
if (!redirectPatchFieldPtr_.valid())
|
||||
{
|
||||
// Construct a patch
|
||||
|
||||
// Make sure to construct the patchfield with uptodate value.
|
||||
OStringStream os;
|
||||
os.writeKeyword("type") << redirectType_ << token::END_STATEMENT
|
||||
<< nl;
|
||||
static_cast<const scalarField&>(*this).writeEntry("value", os);
|
||||
IStringStream is(os.str());
|
||||
dictionary dict(is);
|
||||
Info<< "constructing patchField from :" << dict << endl;
|
||||
|
||||
redirectPatchFieldPtr_.set
|
||||
(
|
||||
fvPatchScalarField::New
|
||||
(
|
||||
patch(),
|
||||
dimensionedInternalField(),
|
||||
dict
|
||||
).ptr()
|
||||
);
|
||||
}
|
||||
return redirectPatchFieldPtr_();
|
||||
}
|
||||
|
||||
|
||||
void Foam::codedFixedValueFvPatchScalarField::updateCoeffs()
|
||||
{
|
||||
if (updated())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure library containing user-defined fvPatchField is uptodate
|
||||
updateLibrary();
|
||||
|
||||
const fvPatchScalarField& fvp = redirectPatchField();
|
||||
|
||||
const_cast<fvPatchScalarField&>(fvp).updateCoeffs();
|
||||
|
||||
// Copy through value
|
||||
operator==(fvp);
|
||||
|
||||
fixedValueFvPatchField<scalar>::updateCoeffs();
|
||||
}
|
||||
|
||||
|
||||
void Foam::codedFixedValueFvPatchScalarField::evaluate
|
||||
(
|
||||
const Pstream::commsTypes commsType
|
||||
)
|
||||
{
|
||||
// Make sure library containing user-defined fvPatchField is uptodate
|
||||
updateLibrary();
|
||||
|
||||
const fvPatchScalarField& fvp = redirectPatchField();
|
||||
|
||||
const_cast<fvPatchScalarField&>(fvp).evaluate(commsType);
|
||||
|
||||
fixedValueFvPatchField<scalar>::evaluate(commsType);
|
||||
}
|
||||
|
||||
|
||||
void Foam::codedFixedValueFvPatchScalarField::write(Ostream& os) const
|
||||
{
|
||||
//dict_.set("value", static_cast<const scalarField&>(*this));
|
||||
//os << dict_ << token::END_STATEMENT << nl;
|
||||
fixedValueFvPatchField<scalar>::write(os);
|
||||
os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT
|
||||
<< nl;
|
||||
if (dict_.found("code"))
|
||||
{
|
||||
os.writeKeyword("code") << string(dict_["code"]) << token::END_STATEMENT
|
||||
<< nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
makePatchTypeField
|
||||
(
|
||||
fvPatchScalarField,
|
||||
codedFixedValueFvPatchScalarField
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,221 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2011 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
|
||||
|
||||
Class
|
||||
Foam::codedFixedValueFvPatchScalarField
|
||||
|
||||
Description
|
||||
Constructs on-the-fly a new boundary condition (derived from
|
||||
fixedValueFvPatchScalarField) which is then used to evaluate.
|
||||
|
||||
See also codeStream.
|
||||
|
||||
Example:
|
||||
|
||||
movingWall
|
||||
{
|
||||
type codedFixedValue;
|
||||
value uniform 0;
|
||||
redirectType rampedFixedValue; // name of generated bc
|
||||
|
||||
code
|
||||
#{
|
||||
operator==(min(10, 0.1*this->db().time().value()));
|
||||
#};
|
||||
|
||||
//codeInclude
|
||||
//#{
|
||||
// #include "fvCFD.H"
|
||||
//#};
|
||||
|
||||
//codeOptions
|
||||
//#{
|
||||
// -I$(LIB_SRC)/finiteVolume/lnInclude
|
||||
//#};
|
||||
|
||||
}
|
||||
|
||||
A special form is if the 'code' section is not supplied. In this case
|
||||
the code gets read from a (runTimeModifiable!) dictionary system/codeDict
|
||||
which would have an entry
|
||||
|
||||
rampedFixedValue
|
||||
{
|
||||
code
|
||||
#{
|
||||
operator==(min(10, 0.1*this->db().time().value()));
|
||||
#};
|
||||
}
|
||||
|
||||
SourceFiles
|
||||
codedFixedValueFvPatchScalarField.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef codedFixedValueFvPatchScalarField_H
|
||||
#define codedFixedValueFvPatchScalarField_H
|
||||
|
||||
#include "fixedValueFvPatchFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class codeProperties;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class codedFixedValueFvPatchScalarField Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class codedFixedValueFvPatchScalarField
|
||||
:
|
||||
public fixedValueFvPatchScalarField
|
||||
{
|
||||
// Private data
|
||||
|
||||
mutable dictionary dict_;
|
||||
|
||||
const word redirectType_;
|
||||
|
||||
mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
const codeProperties& dict() const;
|
||||
|
||||
void writeLibrary
|
||||
(
|
||||
const fileName dir,
|
||||
const fileName libPath,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
void updateLibrary();
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("codedFixedValue");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from patch and internal field
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct from patch, internal field and dictionary
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
//- Construct by mapping given
|
||||
// codedFixedValueFvPatchScalarField
|
||||
// onto a new patch
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const codedFixedValueFvPatchScalarField&,
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&,
|
||||
const fvPatchFieldMapper&
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const codedFixedValueFvPatchScalarField&
|
||||
);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<fvPatchScalarField> clone() const
|
||||
{
|
||||
return tmp<fvPatchScalarField>
|
||||
(
|
||||
new codedFixedValueFvPatchScalarField
|
||||
(
|
||||
*this
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//- Construct as copy setting internal field reference
|
||||
codedFixedValueFvPatchScalarField
|
||||
(
|
||||
const codedFixedValueFvPatchScalarField&,
|
||||
const DimensionedField<scalar, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct and return a clone setting internal field reference
|
||||
virtual tmp<fvPatchScalarField> clone
|
||||
(
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
) const
|
||||
{
|
||||
return tmp<fvPatchScalarField>
|
||||
(
|
||||
new codedFixedValueFvPatchScalarField
|
||||
(
|
||||
*this,
|
||||
iF
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Get reference to the underlying patch
|
||||
const fvPatchScalarField& redirectPatchField() const;
|
||||
|
||||
//- Update the coefficients associated with the patch field
|
||||
virtual void updateCoeffs();
|
||||
|
||||
//- Evaluate the patch field, sets Updated to false
|
||||
virtual void evaluate
|
||||
(
|
||||
const Pstream::commsTypes commsType=Pstream::blocking
|
||||
);
|
||||
|
||||
//- Write
|
||||
virtual void write(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -139,7 +139,6 @@ Foam::pointField Foam::treeDataCell::points() const
|
||||
}
|
||||
|
||||
|
||||
// Check if any point on shape is inside cubeBb.
|
||||
bool Foam::treeDataCell::overlaps
|
||||
(
|
||||
const label index,
|
||||
@ -167,8 +166,6 @@ bool Foam::treeDataCell::contains
|
||||
}
|
||||
|
||||
|
||||
// Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex,
|
||||
// nearestPoint.
|
||||
void Foam::treeDataCell::findNearest
|
||||
(
|
||||
const labelUList& indices,
|
||||
|
||||
Reference in New Issue
Block a user