diff --git a/doc/changes/onTheFly.txt b/doc/changes/onTheFly.txt index 9734c1f5a8..2dc3f5edfa 100644 --- a/doc/changes/onTheFly.txt +++ b/doc/changes/onTheFly.txt @@ -49,7 +49,7 @@ Example: Look up dictionary entries and do some calculation code, codeInclude, codeOptions sections (these are just strings) and calculates the SHA1 checksum of the contents. - it copies a template file -($FOAM_CODESTREAM_TEMPLATE_DIR/codeStreamTemplate.C), substituting all +($FOAM_CODESTREAM_TEMPLATES/codeStreamTemplate.C), substituting all occurences of code, codeInclude, codeOptions. - it writes library source files to constant/codeStream/ and compiles it using 'wmake libso'. diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 155fcea58d..03eefb623b 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -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; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 5a27355410..5eb948eee1 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -57,15 +57,9 @@ namespace functionEntries } -const Foam::word Foam::functionEntries::codeStream::codeTemplateName +const Foam::word Foam::functionEntries::codeStream::codeTemplateC = "codeStreamTemplate.C"; -const Foam::word Foam::functionEntries::codeStream::codeTemplateEnvName - = "FOAM_CODESTREAM_TEMPLATES"; - -const Foam::fileName Foam::functionEntries::codeStream::codeTemplateDirName - = "codeTemplates/codeStream"; - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -148,49 +142,30 @@ bool Foam::functionEntries::codeStream::execute { Info<< "Creating new library in " << libPath << endl; - fileName srcFile; - - // try to get template from FOAM_CODESTREAM_TEMPLATES - fileName templateDir + const fileName fileCsrc ( - Foam::getEnv(codeTemplateEnvName) + codeStreamTools::findTemplate + ( + codeTemplateC + ) ); - if (!templateDir.empty()) - { - srcFile = templateDir/codeTemplateName; - if (!isFile(srcFile, false)) - { - srcFile.clear(); - } - } - - // not found - fallback to ~OpenFOAM expansion - if (srcFile.empty()) - { - srcFile = findEtcFile - ( - codeTemplateDirName/codeTemplateName - ); - } - - if (srcFile.empty()) + // not found! + if (fileCsrc.empty()) { FatalIOErrorIn ( "functionEntries::codeStream::execute(..)", parentDict ) << "Could not find the code template: " - << codeTemplateName << nl - << "Under the $FOAM_CODESTREAM_TEMPLATES directory" - << " via via the ~OpenFOAM/" / codeTemplateDirName - << " expansion" + << codeTemplateC << nl + << codeStreamTools::searchedLocations() << exit(FatalIOError); } List copyFiles(1); - copyFiles[0].file() = srcFile; + copyFiles[0].file() = fileCsrc; copyFiles[0].set("codeInclude", codeInclude); copyFiles[0].set("code", code); @@ -199,7 +174,7 @@ bool Foam::functionEntries::codeStream::execute // Write Make/files filesContents[0].first() = "Make/files"; filesContents[0].second() = - codeTemplateName + "\n" + codeTemplateC + "\n\n" "LIB = $(FOAM_USER_LIBBIN)/lib" + name; // Write Make/options @@ -214,7 +189,7 @@ bool Foam::functionEntries::codeStream::execute ( "functionEntries::codeStream::execute(..)", parentDict - ) << "Failed writing " << endl + ) << "Failed writing " < copyFiles(2); - copyFiles[0].first() = - templates/"fixedValueFvPatchScalarFieldTemplate.C"; - - copyFiles[0].second().setSize(2); - copyFiles[0].second()[0] = Pair("codeInclude", codeInclude); - copyFiles[0].second()[1] = Pair("code", code); - - copyFiles[1].first() = - templates/"fixedValueFvPatchScalarFieldTemplate.H"; + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Could not find one or both code templates: " + << codeTemplateC << ", " << codeTemplateH << nl + << codeStreamTools::searchedLocations() + << exit(FatalIOError); + } - List 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 = "; + List copyFiles(2); + copyFiles[0].file() = fileCsrc; + copyFiles[0].set("codeInclude", codeInclude); + copyFiles[0].set("code", code); - codeStreamTools writer(redirectType_, copyFiles, filesContents); - if (!writer.copyFilesContents(dir)) - { - FatalIOErrorIn - ( - "codedFixedValueFvPatchScalarField::writeLibrary(..)", - dict - ) << "Failed writing " << endl - << copyFiles << endl - << filesContents - << exit(FatalIOError); - } + 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)) + { + FatalIOErrorIn + ( + "codedFixedValueFvPatchScalarField::writeLibrary(..)", + dict + ) << "Failed writing " << nl + << copyFiles << nl + << filesContents + << exit(FatalIOError); } } @@ -221,7 +248,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() { if (Pstream::master()) { - Foam::string wmakeCmd("wmake libso " + dir); + const Foam::string wmakeCmd("wmake libso " + dir); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) { @@ -229,7 +256,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() ( "codedFixedValueFvPatchScalarField::updateLibrary()", dict_ - ) << "Failed " << wmakeCmd << exit(FatalIOError); + ) << "Failed " << wmakeCmd + << exit(FatalIOError); } } @@ -242,7 +270,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary() ( "codedFixedValueFvPatchScalarField::updateLibrary()", dict_ - ) << "Failed loading library " << libPath << exit(FatalIOError); + ) << "Failed loading library " << libPath + << exit(FatalIOError); } } } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H index 9b3ed6debf..25b259b84c 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H @@ -32,7 +32,7 @@ Description See also codeStream. Example: - + \verbatim movingWall { type codedFixedValue; @@ -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 + \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 @@ -86,7 +91,7 @@ namespace Foam class codeProperties; /*---------------------------------------------------------------------------*\ - Class codedFixedValueFvPatchScalarField Declaration + Class codedFixedValueFvPatchScalarField Declaration \*---------------------------------------------------------------------------*/ class codedFixedValueFvPatchScalarField @@ -108,8 +113,8 @@ class codedFixedValueFvPatchScalarField void writeLibrary ( - const fileName dir, - const fileName libPath, + const fileName& dir, + const fileName& libPath, const dictionary& dict ); @@ -117,6 +122,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");