From dce20ade07d96d147d05ce2dc74ee690aa5b4e25 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Feb 2011 16:25:34 +0100 Subject: [PATCH] ENH: compile codedFixedValueFvPatchScalarField into local directory only --- .../functionEntries/codeStream/codeStream.C | 10 +- .../functionEntries/codeStream/codeStream.H | 4 +- .../codeStream/codeStreamTools.H | 6 +- .../derived/codedFixedValue/codeProperties.H | 4 +- .../codedFixedValueFvPatchScalarField.C | 164 ++++++++++-------- 5 files changed, 103 insertions(+), 85 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 9fae385a49..409a9e1fcc 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -106,7 +106,7 @@ bool Foam::functionEntries::codeStream::execute // "code" is mandatory string code = stringOps::trimLeft(codeDict["code"]); - // Create name from the contents + // Create SHA1 digest from the contents SHA1Digest sha; { OSHA1stream os; @@ -196,7 +196,9 @@ bool Foam::functionEntries::codeStream::execute // 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(codeName, copyFiles, filesContents); if (!writer.copyFilesContents(codeDir)) @@ -225,8 +227,8 @@ bool Foam::functionEntries::codeStream::execute } } - bool dummy = true; - reduce(dummy, orOp()); +// bool dummy = true; +// reduce(dummy, orOp()); if (!dlLibraryTable::open(libPath, false)) { diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index 4aaf375b6d..e04bdceaa4 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H @@ -29,7 +29,7 @@ Description generate the entry itself. So - codeStream reads three entries: 'code', 'codeInclude' (optional), 'codeOptions' (optional) - and uses those to generate library sources inside \f 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 \code @@ -123,7 +123,7 @@ public: // Static data members //- Name of the C code template to be used - const static word codeTemplateC; + static const word codeTemplateC; //- Runtime type information diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H index 58f48cf6d0..4bcb7dc7a5 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H @@ -113,15 +113,15 @@ public: //- Name of the code template environment variable // Used to located the codeTemplateName - const static word codeTemplateEnvName; + static const word codeTemplateEnvName; //- Name of the code template sub-directory // Used when locating the codeTemplateName via Foam::findEtcFile - const static fileName codeTemplateDirName; - + static const fileName codeTemplateDirName; static int allowSystemOperations; + // Constructors //- Construct null diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H index 70e770c15a..6916fa362f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codeProperties.H @@ -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(); }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C index 4525e6a3ae..368a9ca8ca 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C @@ -32,6 +32,8 @@ 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" @@ -78,7 +80,7 @@ Foam::codedFixedValueFvPatchScalarField::dict() const void Foam::codedFixedValueFvPatchScalarField::writeLibrary ( - const fileName& dir, + const fileName& codeDir, const fileName& libPath, const dictionary& dict ) @@ -106,73 +108,73 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary // "code" is mandatory string code = stringOps::trimLeft(dict["code"]); - - Info<< "Creating new library in " << libPath << endl; - - const fileName fileCsrc - ( - codeStreamTools::findTemplate - ( - codeTemplateC - ) - ); - - const fileName fileHsrc - ( - codeStreamTools::findTemplate - ( - codeTemplateH - ) - ); - - if (fileCsrc.empty() || fileHsrc.empty()) + // Create SHA1 digest from the contents + SHA1Digest sha; { - FatalIOErrorIn - ( - "codedFixedValueFvPatchScalarField::writeLibrary(..)", - dict - ) << "Could not find one or both code templates: " - << codeTemplateC << ", " << codeTemplateH << nl - << codeStreamTools::searchedLocations() - << exit(FatalIOError); + OSHA1stream os; + os << codeInclude << codeOptions << code; + sha = os.digest(); } - - - List copyFiles(2); - copyFiles[0].file() = fileCsrc; - copyFiles[0].set("codeInclude", codeInclude); - copyFiles[0].set("code", code); - - copyFiles[1].file() = fileHsrc; - - - List filesContents(2); - - // Write Make/files - filesContents[0].first() = "Make/files"; - filesContents[0].second() = - codeTemplateC + "\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)) + if (!codeStreamTools::upToDate(codeDir, sha)) { - FatalIOErrorIn - ( - "codedFixedValueFvPatchScalarField::writeLibrary(..)", - dict - ) << "Failed writing " << nl - << copyFiles << nl - << filesContents - << exit(FatalIOError); + 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 + ) << "Could not find one or both code templates: " + << codeTemplateC << ", " << codeTemplateH << nl + << codeStreamTools::searchedLocations() + << exit(FatalIOError); + } + + + + List copyFiles(2); + copyFiles[0].file() = fileCsrc; + copyFiles[0].set("codeInclude", codeInclude); + copyFiles[0].set("code", code); + + copyFiles[1].file() = fileHsrc; + + + List filesContents(2); + + // Write Make/files + filesContents[0].first() = "Make/files"; + filesContents[0].second() = + codeTemplateC + "\n\n" + "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib/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(codeDir)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Failed writing " << nl + << copyFiles << nl + << filesContents + << exit(FatalIOError); + } } } @@ -192,17 +194,31 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() << exit(FatalIOError); } - const fileName dir = - db().time().constantPath()/"codeStream"/redirectType_; - //Info<< "dir:" << dir << endl; + // local directory for compile/link + const fileName baseDir + ( + stringOps::expandEnv("$FOAM_CASE/codeStream") + ); + // code is written into redirectType_ subdir + const fileName codeDir + ( + baseDir + / redirectType_ + ); + + + //Info<< "codeDir:" << codeDir << endl; + + // library is written into platforms/$WM_OPTIONS/lib subdir const fileName libPath ( - Foam::getEnv("FOAM_USER_LIBBIN") - / "lib" - + redirectType_ - + ".so" + baseDir + / stringOps::expandEnv("platforms/$WM_OPTIONS/lib") + / "lib" + redirectType_ + ".so" ); + + //Info<< "libPath:" << libPath << endl; void* lib = dlLibraryTable::findLibrary(libPath); @@ -211,7 +227,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (!lib) { - writeLibrary(dir, libPath, dict_); + writeLibrary(codeDir, libPath, dict_); } } else @@ -240,7 +256,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() } const dictionary& codeDict = onTheFlyDict.subDict(redirectType_); - writeLibrary(dir, libPath, codeDict); + writeLibrary(codeDir, libPath, codeDict); } } @@ -248,7 +264,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (Pstream::master()) { - const Foam::string wmakeCmd("wmake libso " + dir); + const Foam::string wmakeCmd("wmake libso " + codeDir); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) {