Merge branch 'master' of /home/noisy3/OpenFOAM/OpenFOAM-dev

This commit is contained in:
mattijs
2011-02-23 10:31:10 +00:00
62 changed files with 1385 additions and 224541 deletions

View File

@ -102,7 +102,7 @@ Foam::string Foam::getEnv(const word& envName)
bool Foam::setEnv
(
const word& envName,
const string& value,
const std::string& value,
const bool overwrite
)
{
@ -1066,7 +1066,7 @@ bool Foam::ping(const word& hostname, const label timeOut)
}
int Foam::system(const string& command)
int Foam::system(const std::string& command)
{
return ::system(command.c_str());
}
@ -1084,14 +1084,14 @@ bool Foam::dlClose(void* handle)
}
void* Foam::dlSym(void* handle, const string& symbol)
void* Foam::dlSym(void* handle, const std::string& symbol)
{
void* fun = dlsym(handle, symbol.c_str());
char *error;
if ((error = dlerror()) != NULL)
{
WarningIn("dlSym(void*, const string&)")
WarningIn("dlSym(void*, const std::string&)")
<< "Cannot lookup symbol " << symbol << " : " << error
<< endl;
}

View File

@ -78,6 +78,7 @@ $(strings)/fileName/fileNameIO.C
$(strings)/keyType/keyType.C
$(strings)/wordRe/wordRe.C
$(strings)/lists/hashedWordList.C
$(strings)/stringOps/stringOps.C
primitives/hashes/Hasher/Hasher.C
@ -160,7 +161,6 @@ $(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
@ -198,7 +198,10 @@ $(regIOobject)/regIOobjectWrite.C
db/IOobjectList/IOobjectList.C
db/objectRegistry/objectRegistry.C
db/CallbackRegistry/CallbackRegistryName.C
db/dlLibraryTable/dlLibraryTable.C
dll = db/dynamicLibrary
$(dll)/codeStream/codeStreamTools.C
$(dll)/dlLibraryTable/dlLibraryTable.C
db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C

View File

@ -31,6 +31,7 @@ License
#include "SHA1Digest.H"
#include "OSHA1stream.H"
#include "codeStreamTools.H"
#include "stringOps.H"
#include "dlLibraryTable.H"
#include "OSspecific.H"
#include "Time.H"
@ -56,6 +57,10 @@ namespace functionEntries
}
const Foam::word Foam::functionEntries::codeStream::codeTemplateC
= "codeStreamTemplate.C";
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::codeStream::execute
@ -79,119 +84,121 @@ bool Foam::functionEntries::codeStream::execute
}
// Read three sections of code. Remove any leading empty lines
// (necessary for compilation options, just visually pleasing for includes
// and body).
// Read three sections of code.
// Remove any leading whitespace - necessary for compilation options,
// convenience for includes and body.
dictionary codeDict(is);
string codeInclude = "";
// "codeInclude" is optional
string codeInclude;
if (codeDict.found("codeInclude"))
{
codeInclude = codeStreamTools::stripLeading(codeDict["codeInclude"]);
codeInclude = stringOps::trim(codeDict["codeInclude"]);
}
string code = codeStreamTools::stripLeading(codeDict["code"]);
string codeOptions = "";
// "codeOptions" is optional
string codeOptions;
if (codeDict.found("codeOptions"))
{
codeOptions = codeStreamTools::stripLeading(codeDict["codeOptions"]);
codeOptions = stringOps::trim(codeDict["codeOptions"]);
}
// "code" is mandatory
string code = stringOps::trim(codeDict["code"]);
// Create name out of contents
// Create SHA1 digest from the contents
SHA1Digest sha;
{
OSHA1stream os;
os << codeInclude << code << codeOptions;
os << codeInclude << codeOptions << code;
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"
);
// codeName = prefix + sha1
const fileName codeName = "codeStream_" + sha.str();
// write code into _SHA1 subdir
const fileName codePath = codeStreamTools::codePath("_" + sha.str());
// write library into platforms/$WM_OPTIONS/lib subdir
const fileName libPath = codeStreamTools::libPath(codeName);
void* lib = dlLibraryTable::findLibrary(libPath);
// try to load if not already loaded
if (!lib && dlLibraryTable::open(libPath, false))
{
lib = dlLibraryTable::findLibrary(libPath);
}
// did not load - need to compile it
if (!lib)
{
if (Pstream::master())
{
if (!codeStreamTools::upToDate(dir, sha))
if (!codeStreamTools::upToDate(codePath, sha))
{
Info<< "Creating new library in " << libPath << endl;
fileName templates
const fileName fileCsrc
(
Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR")
codeStreamTools::findTemplate
(
codeTemplateC
)
);
if (!templates.size())
// not found!
if (fileCsrc.empty())
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Please set environment variable"
" FOAM_CODESTREAM_TEMPLATE_DIR"
<< " to point to the location of codeStreamTemplate.C"
) << "Could not find the code template: "
<< codeTemplateC << nl
<< codeStreamTools::searchedLocations()
<< exit(FatalIOError);
}
List<fileAndVars> copyFiles(1);
copyFiles[0].first() = templates/"codeStreamTemplate.C";
stringPairList bodyVars(2);
bodyVars[0] = Pair<string>("codeInclude", codeInclude);
bodyVars[1] = Pair<string>("code", code);
copyFiles[0].second() = bodyVars;
List<fileAndContent> filesContents(2);
List<codeStreamTools::fileAndVars> copyFiles(1);
copyFiles[0].file() = fileCsrc;
copyFiles[0].set("codeInclude", codeInclude);
copyFiles[0].set("code", code);
List<codeStreamTools::fileAndContent> filesContents(2);
// Write Make/files
filesContents[0].first() = "Make/files";
filesContents[0].second() =
"codeStreamTemplate.C \n\
LIB = $(FOAM_USER_LIBBIN)/lib" + name;
codeTemplateC + "\n\n"
+ codeStreamTools::libTarget(codeName);
// Write Make/options
filesContents[1].first() = "Make/options";
filesContents[1].second() =
"EXE_INC = -g\\\n" + codeOptions + "\n\nLIB_LIBS = ";
"EXE_INC = -g \\\n"
+ codeOptions
+ "\n\nLIB_LIBS =";
codeStreamTools writer(name, copyFiles, filesContents);
if (!writer.copyFilesContents(dir))
codeStreamTools writer(codeName, copyFiles, filesContents);
if (!writer.copyFilesContents(codePath))
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed writing " << endl
) << "Failed writing " <<nl
<< copyFiles << endl
<< filesContents
<< exit(FatalIOError);
}
}
Foam::string wmakeCmd("wmake libso " + dir);
const Foam::string wmakeCmd("wmake libso " + codePath);
Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd))
{
@ -199,17 +206,22 @@ bool Foam::functionEntries::codeStream::execute
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed " << wmakeCmd << exit(FatalIOError);
) << "Failed " << wmakeCmd
<< exit(FatalIOError);
}
}
if (!dlLibraryTable::open(libPath))
// bool dummy = true;
// reduce(dummy, orOp<bool>());
if (!dlLibraryTable::open(libPath, false))
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed loading library " << libPath << exit(FatalIOError);
) << "Failed loading library " << libPath
<< exit(FatalIOError);
}
lib = dlLibraryTable::findLibrary(libPath);
@ -224,7 +236,7 @@ bool Foam::functionEntries::codeStream::execute
void (*function)(const dictionary&, Ostream&);
function = reinterpret_cast<void(*)(const dictionary&, Ostream&)>
(
dlSym(lib, name)
dlSym(lib, codeName)
);
if (!function)
@ -233,7 +245,7 @@ bool Foam::functionEntries::codeStream::execute
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed looking up symbol " << name
) << "Failed looking up symbol " << codeName
<< " in library " << lib << exit(FatalIOError);
}

View File

@ -29,11 +29,12 @@ Description
generate the entry itself. So
- codeStream reads three entries: 'code', 'codeInclude' (optional),
'codeOptions' (optional)
and uses those to generate library sources inside constant/codeStream/
and uses those to generate library sources inside \f codeStream/
- these get compiled using 'wmake libso'
- the resulting library is loaded in executed with as arguments
const dictionary& dict,
Ostream& os
\code
(const dictionary& dict, Ostream& os)
\endcode
where the dictionary is the current dictionary.
- the code has to write into Ostream which is then used to construct
the actual dictionary entry.
@ -41,6 +42,7 @@ Description
E.g. to set the internal field of a field:
\verbatim
internalField #codeStream
{
code
@ -56,19 +58,31 @@ Description
#{
#include "fvCFD.H"
#};
//- Optional:
codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude
#};
};
\endverbatim
Note the #{ #} syntax which is just a way of inputting strings with embedded
newlines.
Note the \c \#{ ... \c \#} syntax is a 'verbatim' input mode that allows
inputting strings with embedded newlines.
Limitations:
- '~' symbol not allowed inside the code sections.
- probably some other limitations (uses string::expand which expands $, ~)
- probably some other limitations (uses string::expand which expands
\c \$ and \c ~ sequences)
Note
The code to be compiled is stored under the local \f codeStream directory
with a subdirectory name corresponding to the SHA1 of the contents.
The corresponding library code is located under the local
\f codeStream/platforms/$WM_OPTIONS/lib directory in a library
\f libcodeStream_SHA1.so
SourceFiles
codeStream.C
@ -84,13 +98,11 @@ SourceFiles
namespace Foam
{
class ISstream;
namespace functionEntries
{
/*---------------------------------------------------------------------------*\
Class codeStream Declaration
Class codeStream Declaration
\*---------------------------------------------------------------------------*/
class codeStream
@ -108,6 +120,12 @@ class codeStream
public:
// Static data members
//- Name of the C code template to be used
static const word codeTemplateC;
//- Runtime type information
ClassName("codeStream");

View File

@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "codeStreamTools.H"
#include "stringOps.H"
#include "IFstream.H"
#include "OFstream.H"
#include "OSspecific.H"
@ -39,42 +40,134 @@ int Foam::codeStreamTools::allowSystemOperations
);
const Foam::word Foam::codeStreamTools::codeTemplateEnvName
= "FOAM_CODESTREAM_TEMPLATES";
const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
= "codeTemplates/codeStream";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::codeStreamTools::baseDir()
{
return stringOps::expandEnv("$FOAM_CASE/codeStream");
}
Foam::fileName Foam::codeStreamTools::libSubDir()
{
return stringOps::expandEnv("platforms/$WM_OPTIONS/lib");
}
Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName)
{
return stringOps::expandEnv
(
"$FOAM_CASE/codeStream/" + subDirName
);
}
Foam::fileName Foam::codeStreamTools::libPath(const word& codeName)
{
return stringOps::expandEnv
(
"$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib"
+ codeName + ".so"
);
}
Foam::string Foam::codeStreamTools::libTarget(const word& codeName)
{
return "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/lib" + codeName;
}
Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile)
{
// try to get template from FOAM_CODESTREAM_TEMPLATES
fileName templateDir(Foam::getEnv(codeTemplateEnvName));
fileName file;
if (!templateDir.empty() && isDir(templateDir))
{
file = templateDir/templateFile;
if (!isFile(file, false))
{
file.clear();
}
}
// not found - fallback to ~OpenFOAM expansion
if (file.empty())
{
file = findEtcFile(codeTemplateDirName/templateFile);
}
return file;
}
Foam::string Foam::codeStreamTools::searchedLocations()
{
return
(
"Under the $"
+ codeTemplateDirName
+ " directory or via via the ~OpenFOAM/"
+ codeTemplateDirName
+ " expansion"
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::codeStreamTools::copyAndExpand
(
ISstream& sourceStr,
OSstream& destStr
ISstream& is,
OSstream& os,
const HashTable<string>& mapping
) const
{
if (!sourceStr.good())
if (!is.good())
{
FatalErrorIn
(
"codeStreamTools::copyAndExpand()"
" const"
) << "Failed opening for reading " << sourceStr.name()
) << "Failed opening for reading " << is.name()
<< exit(FatalError);
}
if (!destStr.good())
if (!os.good())
{
FatalErrorIn
(
"codeStreamTools::copyAndExpand()"
" const"
) << "Failed writing " << destStr.name() << exit(FatalError);
) << "Failed writing " << os.name()
<< exit(FatalError);
}
// Copy file whilst rewriting environment vars
// Copy file while rewriting $VARS and ${VARS}
string line;
do
{
sourceStr.getLine(line);
line.expand(true, true); // replace any envvars inside substitutions
destStr<< line.c_str() << nl;
is.getLine(line);
// normal expansion according to mapping
stringOps::inplaceExpand(line, mapping);
// expand according to env variables
stringOps::inplaceExpandEnv(line, true, true);
os << line.c_str() << nl;
}
while (sourceStr.good());
while (is.good());
}
@ -109,11 +202,11 @@ Foam::codeStreamTools::codeStreamTools
{}
Foam::codeStreamTools::codeStreamTools(const codeStreamTools& otf)
Foam::codeStreamTools::codeStreamTools(const codeStreamTools& tools)
:
name_(otf.name_),
copyFiles_(otf.copyFiles_),
filesContents_(otf.filesContents_)
name_(tools.name_),
copyFiles_(tools.copyFiles_),
filesContents_(tools.filesContents_)
{}
@ -127,21 +220,16 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const
(
"codeStreamTools::copyFilesContents(const fileName&) const"
) << "Loading a shared library using case-supplied code is not"
<< " enabled by default" << endl
<< " enabled by default" << nl
<< "because of security issues. If you trust the code you can"
<< " enable this" << endl
<< " enable this" << nl
<< "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
<< " controlDict:" << nl << nl
<< " allowSystemOperations 1" << nl << nl
<< "The system controlDict is either" << nl << nl
<< " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << nl << nl
<< "or" << nl << nl
<< " $WM_PROJECT_DIR/etc/controlDict" << nl
<< endl
<< exit(FatalError);
}
@ -149,98 +237,84 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const
// Create dir
mkDir(dir);
//Info<< "Setting envvar typeName=" << name_ << endl;
setEnv("typeName", name_, true);
// Info<< "set mapping typeName=" << name_ << endl;
// 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].file()).expand());
const fileName destFile(dir/sourceFile.name());
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())
IFstream is(sourceFile);
//Info<< "Reading from " << is.name() << endl;
if (!is.good())
{
FatalErrorIn
(
"codeStreamTools::copyFilesContents()"
"codeStreamTools::copyFilesContents(const fileName&)"
" const"
) << "Failed opening " << sourceFile << exit(FatalError);
}
OFstream destStr(destFile);
OFstream os(destFile);
//Info<< "Writing to " << destFile.name() << endl;
if (!destStr.good())
if (!os.good())
{
FatalErrorIn
(
"codeStreamTools::copyFilesContents()"
"codeStreamTools::copyFilesContents(const fileName&)"
" const"
) << "Failed writing " << destFile << exit(FatalError);
}
copyAndExpand(sourceStr, destStr);
// variables mapping
HashTable<string> mapping(copyFiles_[i]);
mapping.set("typeName", name_);
copyAndExpand(is, os, mapping);
}
// Files that are always written:
forAll(filesContents_, i)
{
fileName f = fileName(dir/filesContents_[i].first()).expand();
const fileName dstFile
(
fileName(dir/filesContents_[i].first()).expand()
);
mkDir(f.path());
OFstream str(f);
mkDir(dstFile.path());
OFstream os(dstFile);
//Info<< "Writing to " << filesContents_[i].first() << endl;
if (!str.good())
if (!os.good())
{
FatalErrorIn
(
"codeStreamTools::copyFilesContents()"
" const"
) << "Failed writing " << f << exit(FatalError);
) << "Failed writing " << dstFile << exit(FatalError);
}
str << filesContents_[i].second().c_str() << endl;
os << 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();
OFstream os(dir/"SHA1Digest");
os << sha1;
return os.good();
}
Foam::SHA1Digest Foam::codeStreamTools::readDigest(const fileName& dir)
{
IFstream str(dir/"SHA1Digest");
return SHA1Digest(str);
IFstream is(dir/"SHA1Digest");
return SHA1Digest(is);
}

View File

@ -39,20 +39,16 @@ SourceFiles
#include "Tuple2.H"
#include "Pair.H"
#include "SHA1Digest.H"
#include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef List<Pair<string> > stringPairList;
typedef Tuple2<fileName, List<Pair<string> > > fileAndVars;
typedef Tuple2<fileName, string> fileAndContent;
class OSstream;
// Forward declaration of classes
class ISstream;
class OSstream;
/*---------------------------------------------------------------------------*\
Class codeStreamTools Declaration
@ -60,24 +56,72 @@ class ISstream;
class codeStreamTools
{
public:
typedef Tuple2<fileName, string> fileAndContent;
//- Helper class for managing file and variables
class fileAndVars
:
public HashTable<string>
{
// Private data
fileName file_;
public:
//- Construct null
fileAndVars()
{}
//- Return the file name
const fileName& file() const
{
return file_;
}
//- Return the file name
fileName& file()
{
return file_;
}
};
private:
// Private data
//- Name for underlying set
word name_;
//- Files to copy
List<fileAndVars> copyFiles_;
List<codeStreamTools::fileAndVars> copyFiles_;
//- Direct contents for files
List<fileAndContent> filesContents_;
protected:
void copyAndExpand(ISstream&, OSstream&) const;
void copyAndExpand
(
ISstream&,
OSstream&,
const HashTable<string>& mapping
) const;
public:
static int allowSystemOperations;
// Static data members
//- Name of the code template environment variable
// Used to located the codeTemplateName
static const word codeTemplateEnvName;
//- Name of the code template sub-directory
// Used when locating the codeTemplateName via Foam::findEtcFile
static const fileName codeTemplateDirName;
static int allowSystemOperations;
// Constructors
@ -96,12 +140,46 @@ public:
);
//- Construct copy
codeStreamTools(const codeStreamTools& otf);
codeStreamTools(const codeStreamTools&);
// Member functions
const List<Tuple2<fileName, List<Pair<string> > > >& copyFiles() const
//- Directory for compile/link (case-specific)
// Expanded from \$FOAM_CASE/codeStream
static fileName baseDir();
//- Subdirectory name for library
// Expanded from platforms/\$WM_OPTIONS/lib
static fileName libSubDir();
//- Local path for specified code name
// Expanded from \$FOAM_CASE/codeStream
static fileName codePath(const word& subDirName);
//- Local library path for specified code name
// Expanded from \$FOAM_CASE/platforms/\$WM_OPTIONS/lib
static fileName libPath(const word& codeName);
//- The library target path for Make/files
static string libTarget(const word& codeName);
//- Find a code-template via the codeTemplateEnvName
// alternatively in the codeTemplateDirName via Foam::findEtcFile
static fileName findTemplate(const word& templateName);
//- List searched locations in a format suitable for display an error
static string searchedLocations();
const word& name() const
{
return name_;
}
const List<fileAndVars>& copyFiles() const
{
return copyFiles_;
}
@ -111,16 +189,10 @@ public:
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 void* findLibrary(const fileName& libPath);
static bool writeDigest(const fileName& dir, const SHA1Digest& sha1);
static SHA1Digest readDigest(const fileName& dir);

View File

@ -62,7 +62,11 @@ Foam::dlLibraryTable::~dlLibraryTable()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::dlLibraryTable::open(const fileName& functionLibName)
bool Foam::dlLibraryTable::open
(
const fileName& functionLibName,
const bool verbose
)
{
if (functionLibName.size())
{
@ -70,11 +74,14 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName)
if (!functionLibPtr)
{
WarningIn
(
"dlLibraryTable::open(const fileName& functionLibName)"
) << "could not load " << functionLibName
<< endl;
if (verbose)
{
WarningIn
(
"dlLibraryTable::open(const fileName&)"
) << "could not load " << functionLibName
<< endl;
}
return false;
}
@ -97,7 +104,11 @@ bool Foam::dlLibraryTable::open(const fileName& functionLibName)
}
bool Foam::dlLibraryTable::close(const fileName& functionLibName)
bool Foam::dlLibraryTable::close
(
const fileName& functionLibName,
const bool verbose
)
{
void* libPtr = findLibrary(functionLibName);
if (libPtr)
@ -106,11 +117,14 @@ bool Foam::dlLibraryTable::close(const fileName& functionLibName)
if (!dlClose(libPtr))
{
WarningIn
(
"dlLibraryTable::close(const fileName& functionLibName)"
) << "could not close " << functionLibName
<< endl;
if (verbose)
{
WarningIn
(
"dlLibraryTable::close(const fileName&)"
) << "could not close " << functionLibName
<< endl;
}
return false;
}
@ -144,7 +158,7 @@ bool Foam::dlLibraryTable::open
{
fileNameList libNames(dict.lookup(libsEntry));
bool allOpened = (libNames.size() > 0);
bool allOpened = !libNames.empty();
forAll(libNames, i)
{

View File

@ -94,11 +94,11 @@ public:
// Member Functions
//- Open the named library
static bool open(const fileName& name);
//- Open the named library, optionally with warnings if problems occur
static bool open(const fileName& name, const bool verbose = true);
//- Close the named library
static bool close(const fileName& name);
//- Close the named library, optionally with warnings if problems occur
static bool close(const fileName& name, const bool verbose = true);
//- Find the handle of the named library
static void* findLibrary(const fileName& name);
@ -109,7 +109,7 @@ public:
//- Open all the libraries listed in the 'libsEntry' entry in the
// given dictionary if present and check the additions
// to the give constructor table
// to the given constructor table
template<class TablePtr>
static bool open
(

View File

@ -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

View File

@ -65,7 +65,7 @@ bool env(const word&);
string getEnv(const word&);
//- Set an environment variable
bool setEnv(const word& name, const string& value, const bool overwrite);
bool setEnv(const word& name, const std::string& value, const bool overwrite);
//- Return the system's host name, as per hostname(1)
// Optionally with the full name (as per the '-f' option)
@ -182,7 +182,7 @@ bool ping(const word&, const label port, const label timeOut);
bool ping(const word&, const label timeOut=10);
//- Execute the specified command
int system(const string& command);
int system(const std::string& command);
//- open a shared library. Return handle to library
void* dlOpen(const fileName& lib);
@ -191,7 +191,7 @@ void* dlOpen(const fileName& lib);
bool dlClose(void*);
//- Lookup a symbol in a dlopened library using handle
void* dlSym(void* handle, const string& symbol);
void* dlSym(void* handle, const std::string& symbol);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -550,7 +550,7 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
Foam::labelHashSet Foam::polyBoundaryMesh::patchSet
(
const wordReList& patchNames,
const UList<wordRe>& patchNames,
const bool warnNotFound
) const
{

View File

@ -38,7 +38,6 @@ SourceFiles
#include "polyPatchList.H"
#include "regIOobject.H"
#include "labelPair.H"
#include "wordReList.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,7 +45,9 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
class polyMesh;
class wordRe;
// Forward declaration of friend functions and operators
@ -171,7 +172,7 @@ public:
// By default warns if given names are not found.
labelHashSet patchSet
(
const wordReList& patchNames,
const UList<wordRe>& patchNames,
const bool warnNotFound = true
) const;

View File

@ -101,6 +101,22 @@ bool Foam::SHA1Digest::empty() const
}
std::string Foam::SHA1Digest::str() const
{
std::string buf;
buf.resize(length*2);
unsigned nChar = 0;
for (unsigned i = 0; i < length; ++i)
{
buf[nChar++] = hexChars[((v_[i] >> 4) & 0xF)];
buf[nChar++] = hexChars[(v_[i] & 0xF)];
}
return buf;
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const

View File

@ -80,6 +80,9 @@ public:
//- Return true if the digest is empty (ie, all zero).
bool empty() const;
//- Return string representation
std::string str() const;
//- Equality operator
bool operator==(const SHA1Digest&) const;

View File

@ -96,75 +96,79 @@ Foam::string& Foam::string::replaceAll
// Expand all occurences of environment variables and initial tilde sequences
Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
{
size_type startEnvar = 0;
size_type begVar = 0;
// Expand $VARS
// Repeat until nothing more is found
while
(
(startEnvar = find('$', startEnvar)) != npos
&& startEnvar < size()-1
(begVar = find('$', begVar)) != npos
&& begVar < size()-1
)
{
if (startEnvar == 0 || operator[](startEnvar-1) != '\\')
if (begVar == 0 || operator[](begVar-1) != '\\')
{
// Find end of first occurrence
size_type endEnvar = startEnvar;
size_type nd = 0;
size_type endVar = begVar;
size_type delim = 0;
if (operator[](startEnvar+1) == '{')
if (operator[](begVar+1) == '{')
{
endEnvar = find('}', startEnvar);
nd = 1;
endVar = find('}', begVar);
delim = 1;
}
else
{
iterator iter = begin() + startEnvar + 1;
iterator iter = begin() + begVar + 1;
while (iter != end() && (isalnum(*iter) || *iter == '_'))
while
(
iter != end()
&& (isalnum(*iter) || *iter == '_')
)
{
++iter;
++endEnvar;
++endVar;
}
}
if (endEnvar != npos && endEnvar != startEnvar)
if (endVar != npos && endVar != begVar)
{
string enVar = substr
string varName = substr
(
startEnvar + 1 + nd,
endEnvar - startEnvar - 2*nd
begVar + 1 + delim,
endVar - begVar - 2*delim
);
string enVarString = getEnv(enVar);
string varValue = getEnv(varName);
if (enVarString.size())
if (varValue.size())
{
if (recurse)
{
enVarString.expand(recurse, allowEmptyVar);
varValue.expand(recurse, allowEmptyVar);
}
std::string::replace
(
startEnvar,
endEnvar - startEnvar + 1,
enVarString
begVar,
endVar - begVar + 1,
varValue
);
startEnvar += enVarString.size();
begVar += varValue.size();
}
else if (allowEmptyVar)
{
std::string::replace
(
startEnvar,
endEnvar - startEnvar + 1,
begVar,
endVar - begVar + 1,
""
);
}
else
{
FatalErrorIn("string::expand(const bool, const bool)")
<< "Unknown variable name " << enVar << '.'
<< "Unknown variable name " << varName << '.'
<< exit(FatalError);
}
}
@ -175,7 +179,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
}
else
{
startEnvar++;
++begVar;
}
}
@ -191,10 +195,10 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
word user;
fileName file;
if ((startEnvar = find('/')) != npos)
if ((begVar = find('/')) != npos)
{
user = substr(1, startEnvar - 1);
file = substr(startEnvar + 1);
user = substr(1, begVar - 1);
file = substr(begVar + 1);
}
else
{
@ -215,7 +219,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
}
else if (operator[](0) == '.')
{
// Expand initial '.' and './' into cwd
// Expand a lone '.' and an initial './' into cwd
if (size() == 1)
{
*this = cwd();

View File

@ -0,0 +1,383 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "stringOps.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::string Foam::stringOps::expand
(
const string& original,
const HashTable<string, word, string::hash>& mapping,
const char sigil
)
{
string s(original);
return inplaceExpand(s, mapping);
}
Foam::string& Foam::stringOps::inplaceExpand
(
string& s,
const HashTable<string, word, string::hash>& mapping,
const char sigil
)
{
string::size_type begVar = 0;
// Expand $VAR or ${VAR}
// Repeat until nothing more is found
while
(
(begVar = s.find(sigil, begVar)) != string::npos
&& begVar < s.size()-1
)
{
if (begVar == 0 || s[begVar-1] != '\\')
{
// Find end of first occurrence
string::size_type endVar = begVar;
string::size_type delim = 0;
if (s[begVar+1] == '{')
{
endVar = s.find('}', begVar);
delim = 1;
}
else
{
string::iterator iter = s.begin() + begVar + 1;
while
(
iter != s.end()
&& (isalnum(*iter) || *iter == '_')
)
{
++iter;
++endVar;
}
}
if (endVar != string::npos && endVar != begVar)
{
string varName = s.substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
);
HashTable<string, word, string::hash>::const_iterator fnd =
mapping.find(varName);
if (fnd != HashTable<string, word, string::hash>::end())
{
s.std::string::replace
(
begVar,
endVar - begVar + 1,
*fnd
);
begVar += (*fnd).size();
}
else
{
s.std::string::replace
(
begVar,
endVar - begVar + 1,
""
);
}
}
else
{
break;
}
}
else
{
++begVar;
}
}
return s;
}
Foam::string Foam::stringOps::expandEnv
(
const string& original,
const bool recurse,
const bool allowEmptyVar
)
{
string s(original);
return inplaceExpandEnv(s, recurse, allowEmptyVar);
}
// Expand all occurences of environment variables and initial tilde sequences
Foam::string& Foam::stringOps::inplaceExpandEnv
(
string& s,
const bool recurse,
const bool allowEmptyVar
)
{
string::size_type begVar = 0;
// Expand $VARS
// Repeat until nothing more is found
while
(
(begVar = s.find('$', begVar)) != string::npos
&& begVar < s.size()-1
)
{
if (begVar == 0 || s[begVar-1] != '\\')
{
// Find end of first occurrence
string::size_type endVar = begVar;
string::size_type delim = 0;
if (s[begVar+1] == '{')
{
endVar = s.find('}', begVar);
delim = 1;
}
else
{
string::iterator iter = s.begin() + begVar + 1;
while
(
iter != s.end()
&& (isalnum(*iter) || *iter == '_')
)
{
++iter;
++endVar;
}
}
if (endVar != string::npos && endVar != begVar)
{
string varName = s.substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
);
string varValue = getEnv(varName);
if (varValue.size())
{
if (recurse)
{
varValue.expand(recurse, allowEmptyVar);
}
s.std::string::replace
(
begVar,
endVar - begVar + 1,
varValue
);
begVar += varValue.size();
}
else if (allowEmptyVar)
{
s.std::string::replace
(
begVar,
endVar - begVar + 1,
""
);
}
else
{
FatalErrorIn("string::expand(const bool, const bool)")
<< "Unknown variable name " << varName << '.'
<< exit(FatalError);
}
}
else
{
break;
}
}
else
{
++begVar;
}
}
if (!s.empty())
{
if (s[0] == '~')
{
// Expand initial ~
// ~/ => home directory
// ~OpenFOAM => site/user OpenFOAM configuration directory
// ~user => home directory for specified user
word user;
fileName file;
if ((begVar = s.find('/')) != string::npos)
{
user = s.substr(1, begVar - 1);
file = s.substr(begVar + 1);
}
else
{
user = s.substr(1);
}
// NB: be a bit lazy and expand ~unknownUser as an
// empty string rather than leaving it untouched.
// otherwise add extra test
if (user == "OpenFOAM")
{
s = findEtcFile(file);
}
else
{
s = home(user)/file;
}
}
else if (s[0] == '.')
{
// Expand a lone '.' and an initial './' into cwd
if (s.size() == 1)
{
s = cwd();
}
else if (s[1] == '/')
{
s.std::string::replace(0, 1, cwd());
}
}
}
return s;
}
Foam::string Foam::stringOps::trimLeft(const string& s)
{
if (!s.empty())
{
string::size_type beg = 0;
while (isspace(s[beg]))
{
++beg;
}
if (beg)
{
return s.substr(beg);
}
}
return s;
}
Foam::string& Foam::stringOps::inplaceTrimLeft(string& s)
{
if (!s.empty())
{
string::size_type beg = 0;
while (isspace(s[beg]))
{
++beg;
}
if (beg)
{
s.erase(0, beg);
}
}
return s;
}
Foam::string Foam::stringOps::trimRight(const string& s)
{
if (!s.empty())
{
string::size_type sz = s.size();
while (sz && isspace(s[sz-1]))
{
--sz;
}
if (sz < s.size())
{
return s.substr(0, sz);
}
}
return s;
}
Foam::string& Foam::stringOps::inplaceTrimRight(string& s)
{
if (!s.empty())
{
string::size_type sz = s.size();
while (sz && isspace(s[sz-1]))
{
--sz;
}
s.resize(sz);
}
return s;
}
Foam::string Foam::stringOps::trim(const string& original)
{
return trimLeft(trimRight(original));
}
Foam::string& Foam::stringOps::inplaceTrim(string& s)
{
inplaceTrimRight(s);
inplaceTrimLeft(s);
return s;
}
// ************************************************************************* //

View File

@ -0,0 +1,159 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
Namespace
Foam::stringOps
Description
Collection of static functions to do various simple string-related
operations
SourceFiles
stringOps.C
\*---------------------------------------------------------------------------*/
#ifndef stringOps_H
#define stringOps_H
#include "string.H"
#include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Namespace stringOps Declaration
\*---------------------------------------------------------------------------*/
namespace stringOps
{
//- Expand occurences of variables according to the mapping
// Expansion includes:
// -# variables
// - "$VAR", "${VAR}"
//
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string expand
(
const string&,
const HashTable<string, word, string::hash>& mapping,
const char sigil = '$'
);
//- Inplace expand occurences of variables according to the mapping
// Expansion includes:
// -# variables
// - "$VAR", "${VAR}"
//
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string& inplaceExpand
(
string&,
const HashTable<string, word, string::hash>& mapping,
const char sigil = '$'
);
//- Expand initial tildes and all occurences of environment variables
// Expansion includes:
// -# environment variables
// - "$VAR", "${VAR}"
// -# current directory
// - leading "./" : the current directory
// -# tilde expansion
// - leading "~/" : home directory
// - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
//
// \sa
// Foam::findEtcFile
string expandEnv
(
const string&,
const bool recurse=false,
const bool allowEmptyVar = false
);
//- Expand initial tildes and all occurences of environment variables
// Expansion includes:
// -# environment variables
// - "$VAR", "${VAR}"
// -# current directory
// - leading "./" : the current directory
// -# tilde expansion
// - leading "~/" : home directory
// - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
//
// \sa
// Foam::findEtcFile
string& inplaceExpandEnv
(
string&,
const bool recurse=false,
const bool allowEmptyVar = false
);
//- Return string trimmed of leading whitespace
string trimLeft(const string&);
//- Trim leading whitespace inplace
string& inplaceTrimLeft(string&);
//- Return string trimmed of trailing whitespace
// NOT IMPLEMENTED
string trimRight(const string&);
//- Trim trailing whitespace inplace
// NOT IMPLEMENTED
string& inplaceTrimRight(string&);
//- Return string trimmed of leading and trailing whitespace
// NOT IMPLEMENTED
string trim(const string&);
//- Trim leading and trailing whitespace inplace
// NOT IMPLEMENTED
string& inplaceTrim(string&);
} // End namespace stringOps
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -44,7 +44,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class codeProperties Declaration
Class codeProperties Declaration
\*---------------------------------------------------------------------------*/
class codeProperties
@ -79,7 +79,7 @@ public:
modified_ = false;
}
//- Read the solution dictionary
//- Read the dictionary
virtual bool read();
};

View File

@ -32,8 +32,20 @@ License
#include "dlLibraryTable.H"
#include "IFstream.H"
#include "OFstream.H"
#include "SHA1Digest.H"
#include "OSHA1stream.H"
#include "codeStreamTools.H"
#include "codeProperties.H"
#include "stringOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::codedFixedValueFvPatchScalarField::codeTemplateC
= "fixedValueFvPatchScalarFieldTemplate.C";
const Foam::word Foam::codedFixedValueFvPatchScalarField::codeTemplateH
= "fixedValueFvPatchScalarFieldTemplate.H";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -68,81 +80,103 @@ Foam::codedFixedValueFvPatchScalarField::dict() const
void Foam::codedFixedValueFvPatchScalarField::writeLibrary
(
const fileName dir,
const fileName libPath,
const fileName& codePath,
const fileName& libPath,
const dictionary& dict
)
{
Info<< "Creating new library in " << libPath << endl;
// Write files for new library
if (Pstream::master())
if (!Pstream::master())
{
fileName templates(Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR"));
if (!templates.size())
return;
}
// "codeInclude" is optional
string codeInclude;
if (dict.found("codeInclude"))
{
codeInclude = stringOps::trim(dict["codeInclude"]);
}
// "codeOptions" is optional
string codeOptions;
if (dict.found("codeOptions"))
{
codeOptions = stringOps::trim(dict["codeOptions"]);
}
// "code" is mandatory
string code = stringOps::trim(dict["code"]);
// Create SHA1 digest from the contents
SHA1Digest sha;
{
OSHA1stream os;
os << codeInclude << codeOptions << code;
sha = os.digest();
}
// Info<<"old SHA1: " << sha1_ << nl
// <<"new SHA1: " << sha << endl;
// (void) codeStreamTools::upToDate(codePath, sha)
// TODO: compile on-demand
if (true)
{
Info<< "Creating new library in " << libPath << endl;
const fileName fileCsrc(codeStreamTools::findTemplate(codeTemplateC));
const fileName fileHsrc(codeStreamTools::findTemplate(codeTemplateH));
// not found!
if (fileCsrc.empty() || fileHsrc.empty())
{
FatalIOErrorIn
(
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
dict
) << "Please set environment variable"
<< " FOAM_CODESTREAM_TEMPLATE_DIR"
<< " to point to the location of "
<< "fixedValueFvPatchScalarFieldTemplate.C"
) << "Could not find one or both code templates: "
<< codeTemplateC << ", " << codeTemplateH << nl
<< codeStreamTools::searchedLocations()
<< 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<codeStreamTools::fileAndVars> copyFiles(2);
copyFiles[0].file() = fileCsrc;
copyFiles[0].set("codeInclude", codeInclude);
copyFiles[0].set("code", code);
copyFiles[1].file() = fileHsrc;
List<fileAndVars> copyFiles(2);
copyFiles[0].first() =
templates/"fixedValueFvPatchScalarFieldTemplate.C";
List<codeStreamTools::fileAndContent> filesContents(2);
copyFiles[0].second().setSize(2);
copyFiles[0].second()[0] = Pair<string>("codeInclude", codeInclude);
copyFiles[0].second()[1] = Pair<string>("code", 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_;
codeTemplateC + "\n\n"
+ codeStreamTools::libTarget(redirectType_);
// Write Make/options
filesContents[1].first() = "Make/options";
filesContents[1].second() =
"EXE_INC = -g\\\n -I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
"EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
+ codeOptions
+ "\n\nLIB_LIBS = ";
codeStreamTools writer(redirectType_, copyFiles, filesContents);
if (!writer.copyFilesContents(dir))
if (!writer.copyFilesContents(codePath))
{
FatalIOErrorIn
(
"codedFixedValueFvPatchScalarField::writeLibrary(..)",
dict
) << "Failed writing " << endl
<< copyFiles << endl
) << "Failed writing " << nl
<< copyFiles << nl
<< filesContents
<< exit(FatalIOError);
}
@ -165,18 +199,20 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
<< exit(FatalIOError);
}
const fileName dir =
db().time().constantPath()/"codeStream"/redirectType_;
//Info<< "dir:" << dir << endl;
// write code into redirectType_ subdir
const fileName codePath = codeStreamTools::codePath(redirectType_);
const fileName libPath
(
Foam::getEnv("FOAM_USER_LIBBIN")
/ "lib"
+ redirectType_
+ ".so"
);
//Info<< "libPath:" << libPath << endl;
// const fileName oldLibPath = codeStreamTools::libPath
// (
// redirectType_ + "_" + sha1_
// );
// write library into platforms/$WM_OPTIONS/lib subdir
const fileName libPath = codeStreamTools::libPath(redirectType_);
//Info<< "codePath:" << codePath << nl
// << "libPath:" << libPath << endl;
void* lib = dlLibraryTable::findLibrary(libPath);
@ -184,7 +220,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
{
if (!lib)
{
writeLibrary(dir, libPath, dict_);
writeLibrary(codePath, libPath, dict_);
}
}
else
@ -213,7 +249,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
}
const dictionary& codeDict = onTheFlyDict.subDict(redirectType_);
writeLibrary(dir, libPath, codeDict);
writeLibrary(codePath, libPath, codeDict);
}
}
@ -221,7 +257,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
{
if (Pstream::master())
{
Foam::string wmakeCmd("wmake libso " + dir);
const Foam::string wmakeCmd("wmake libso " + codePath);
Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd))
{
@ -229,7 +265,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
(
"codedFixedValueFvPatchScalarField::updateLibrary()",
dict_
) << "Failed " << wmakeCmd << exit(FatalIOError);
) << "Failed " << wmakeCmd
<< exit(FatalIOError);
}
}
@ -242,7 +279,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
(
"codedFixedValueFvPatchScalarField::updateLibrary()",
dict_
) << "Failed loading library " << libPath << exit(FatalIOError);
) << "Failed loading library " << libPath
<< exit(FatalIOError);
}
}
}

View File

@ -32,7 +32,7 @@ Description
See also codeStream.
Example:
\verbatim
movingWall
{
type codedFixedValue<scalar>;
@ -53,13 +53,14 @@ Description
//#{
// -I$(LIB_SRC)/finiteVolume/lnInclude
//#};
}
\endverbatim
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
which would have a corresponding entry
\verbatim
rampedFixedValue
{
code
@ -67,6 +68,10 @@ Description
operator==(min(10, 0.1*this->db().time().value()));
#};
}
\endverbatim
SeeAlso
Foam::codeStreamTools for constant paths used
SourceFiles
codedFixedValueFvPatchScalarField.C
@ -77,6 +82,7 @@ SourceFiles
#define codedFixedValueFvPatchScalarField_H
#include "fixedValueFvPatchFields.H"
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -86,7 +92,7 @@ namespace Foam
class codeProperties;
/*---------------------------------------------------------------------------*\
Class codedFixedValueFvPatchScalarField Declaration
Class codedFixedValueFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class codedFixedValueFvPatchScalarField
@ -95,8 +101,13 @@ class codedFixedValueFvPatchScalarField
{
// Private data
//- Dictionary contents for the boundary condition
mutable dictionary dict_;
//- SHA1Digest of the Dictionary contents
// Currently unused, but useful for reloading?
mutable SHA1Digest sha1_;
const word redirectType_;
mutable autoPtr<fvPatchScalarField> redirectPatchFieldPtr_;
@ -108,8 +119,8 @@ class codedFixedValueFvPatchScalarField
void writeLibrary
(
const fileName dir,
const fileName libPath,
const fileName& dir,
const fileName& libPath,
const dictionary& dict
);
@ -117,6 +128,15 @@ class codedFixedValueFvPatchScalarField
public:
// Static data members
//- Name of the C code template to be used
const static word codeTemplateC;
//- Name of the H code template to be used
const static word codeTemplateH;
//- Runtime type information
TypeName("codedFixedValue<scalar>");

View File

@ -7,4 +7,3 @@ LIB_LIBS = \
-lfiniteVolume \
-lOpenFOAM \
-lmeshTools

View File

@ -71,7 +71,11 @@ Foam::ParticleForceList<CloudType>::ParticleForceList
forAllConstIter(wordHashSet, models, iter)
{
const word& model = iter.key();
set(i, ParticleForce<CloudType>::New(owner, mesh, dict, model));
this->set
(
i,
ParticleForce<CloudType>::New(owner, mesh, dict, model)
);
i++;
}
}

View File

@ -41,7 +41,7 @@ const
"const"
) << "gradU field not allocated" << abort(FatalError);
return reinterpret_cast<const volTensorField>(0);
return *reinterpret_cast<const volTensorField*>(0);
}
}

View File

@ -72,7 +72,7 @@ Foam::BrownianMotionForce<CloudType>::BrownianMotionForce
if (turbulence_)
{
HashTable<const compressible::turbulenceModel*> models =
this->mesh().objectRegistry::lookupClass
this->mesh().objectRegistry::template lookupClass
<
compressible::turbulenceModel
>();

View File

@ -24,16 +24,14 @@ License
\*---------------------------------------------------------------------------*/
#include "nearWallFields.H"
#include "wordReList.H"
//#include "volFields.H"
//#include "selfContainedDirectMappedFixedValueFvPatchFields.H"
//#include "interpolationCellPoint.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(nearWallFields, 0);
}
defineTypeNameAndDebug(Foam::nearWallFields, 0);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -87,7 +85,10 @@ void Foam::nearWallFields::read(const dictionary& dict)
const fvMesh& mesh = refCast<const fvMesh>(obr_);
dict.lookup("fields") >> fieldSet_;
patchSet_ = mesh.boundaryMesh().patchSet(dict.lookup("patches"));
patchSet_ = mesh.boundaryMesh().patchSet
(
wordReList(dict.lookup("patches"))
);
distance_ = readScalar(dict.lookup("distance"));

View File

@ -27,6 +27,7 @@ License
#include "volFields.H"
#include "dictionary.H"
#include "Time.H"
#include "wordReList.H"
#include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H"
#include "incompressible/RAS/RASModel/RASModel.H"
@ -229,7 +230,10 @@ void Foam::forces::read(const dictionary& dict)
const fvMesh& mesh = refCast<const fvMesh>(obr_);
patchSet_ = mesh.boundaryMesh().patchSet(dict.lookup("patches"));
patchSet_ = mesh.boundaryMesh().patchSet
(
wordReList(dict.lookup("patches"))
);
if (directForceDensity_)
{

View File

@ -34,4 +34,3 @@ derivedFvPatchFields/radiationCoupledBase/radiationCoupledBase.C
derivedFvPatchFields/greyDiffusiveViewFactor/greyDiffusiveViewFactorFixedValueFvPatchScalarField.C
LIB = $(FOAM_LIBBIN)/libradiationModels

View File

@ -23,5 +23,3 @@ LIB_LIBS = \
-lliquidMixtureProperties \
-lsolidProperties \
-lliquidProperties