View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002240 | OpenFOAM | Bug | public | 2016-09-09 11:57 | 2016-09-09 12:34 |
Reporter | MattijsJ | Assigned To | henry | ||
Priority | low | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | GNU/Linux | OS | OpenSuSE | OS Version | 13.2 |
Product Version | dev | ||||
Fixed in Version | dev | ||||
Summary | 0002240: codedSource derives from cellSetOption but cannot use it | ||||
Description | codedSource derives from cellSetOption but the dynamically generated version does not. Hence the instantiated version cannot use the cell selection mechanism. Choices: 1. make generated version derive from cellSetOption as well 2. or have codedSource (derived from option) and new codedCellSource (derived from cellSetOption) | ||||
Tags | No tags attached. | ||||
|
codedFvOptionTemplate.C (4,722 bytes)
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation \\/ 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 "codedFvOptionTemplate.H" #include "addToRunTimeSelectionTable.H" #include "fvPatchFieldMapper.H" #include "volFields.H" #include "surfaceFields.H" #include "unitConversion.H" #include "fvMatrix.H" //{{{ begin codeInclude ${codeInclude} //}}} end codeInclude // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { namespace fv { // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // //{{{ begin localCode ${localCode} //}}} end localCode // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // extern "C" { // dynamicCode: // SHA1 = ${SHA1sum} // // unique function name that can be checked if the correct library version // has been loaded void ${typeName}_${SHA1sum}(bool load) { if (load) { // code that can be explicitly executed after loading } else { // code that can be explicitly executed before unloading } } } // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // //makeRemovablePatchTypeField //( // fvPatch${FieldType}, // ${typeName}FvOption${SourceType} //); defineTypeNameAndDebug(${typeName}FvOption${SourceType}, 0); addRemovableToRunTimeSelectionTable ( option, ${typeName}FvOption${SourceType}, dictionary ); const char* const ${typeName}FvOption${SourceType}::SHA1sum = "${SHA1sum}"; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // ${typeName}FvOption${SourceType}:: ${typeName}FvOption${SourceType} ( const word& name, const word& modelType, const dictionary& dict, const fvMesh& mesh ) : cellSetOption(name, modelType, dict, mesh) { if (${verbose:-false}) { Info<<"construct ${typeName} sha1: ${SHA1sum}" " from components\n"; } } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // ${typeName}FvOption${SourceType}:: ~${typeName}FvOption${SourceType}() { if (${verbose:-false}) { Info<<"destroy ${typeName} sha1: ${SHA1sum}\n"; } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void ${typeName}FvOption${SourceType}::correct ( GeometricField<${TemplateType}, fvPatchField, volMesh>& fld ) { if (${verbose:-false}) { Info<<"${typeName}FvOption${SourceType}::correct()\n"; } //{{{ begin code ${codeCorrect} //}}} end code } void ${typeName}FvOption${SourceType}::addSup ( fvMatrix<${TemplateType}>& eqn, const label fieldi ) { if (${verbose:-false}) { Info<<"${typeName}FvOption${SourceType}::addSup()\n"; } //{{{ begin code ${codeAddSup} //}}} end code } void ${typeName}FvOption${SourceType}::addSup ( const volScalarField& rho, fvMatrix<${TemplateType}>& eqn, const label fieldi ) { if (${verbose:-false}) { Info<<"${typeName}FvOption${SourceType}::addSup()\n"; } //{{{ begin code ${codeAddSup} //}}} end code } void ${typeName}FvOption${SourceType}::setValue ( fvMatrix<${TemplateType}>& eqn, const label fieldi ) { if (${verbose:-false}) { Info<<"${typeName}FvOption${SourceType}::setValue()\n"; } //{{{ begin code ${codeSetValue} //}}} end code } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam } // End namespace fv // ************************************************************************* // |
|
codedFvOptionTemplate.H (4,913 bytes)
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation \\/ 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/>. Description Template for use with dynamic code generation of a source. The hook functions take the following arguments: codeCorrect ( GeometricField<Type, fvPatchField, volMesh>& fld ) codeAddSup ( fvMatrix<Type}>& eqn, const label fieldi ) setValue ( fvMatrix<Type}>& eqn, const label fieldi ) where : fld is the field in fieldNames eqn is the fvMatrix energySource { type scalarCodedSource; active true; selectionMode all; scalarCodedSourceCoeffs { fieldNames (h); name sourceTime; codeInclude #{ #}; codeCorrect #{ Pout<< "**codeCorrect**" << endl; #}; codeAddSup #{ const Time& time = mesh().time(); const scalarField& V = mesh_.V(); scalarField& heSource = eqn.source(); heSource -= 0.1*sqr(time.value())*V; #}; codeSetValue #{ Pout<< "**codeSetValue**" << endl; #}; // Dummy entry. Make dependent on above to trigger recompilation code #{ $codeInclude $codeCorrect $codeAddSup $codeSetValue #}; } sourceTimeCoeffs { // Dummy entry } } SourceFiles codedFvOptionTemplate.C \*---------------------------------------------------------------------------*/ #ifndef codedFvOptionTemplate_H #define codedFvOptionTemplate_H #include "cellSetOption.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { namespace fv { /*---------------------------------------------------------------------------*\ A templated CodedFvOption \*---------------------------------------------------------------------------*/ class ${typeName}FvOption${SourceType} : public cellSetOption { public: //- Information about the SHA1 of the code itself static const char* const SHA1sum; //- Runtime type information TypeName("${typeName}"); // Constructors //- Construct from patch and internal field ${typeName}FvOption${SourceType} ( const word& name, const word& modelType, const dictionary& dict, const fvMesh& mesh ); //- Destructor virtual ~${typeName}FvOption${SourceType}(); // Member functions //- Correct field virtual void correct ( GeometricField<${TemplateType}, fvPatchField, volMesh>& ); //- Explicit and implicit matrix contributions virtual void addSup ( fvMatrix<${TemplateType}>& eqn, const label fieldi ); //- Explicit and implicit matrix contributions for compressible // equations virtual void addSup ( const volScalarField& rho, fvMatrix<${TemplateType}>& eqn, const label fieldi ); //- Set value virtual void setValue ( fvMatrix<${TemplateType}>& eqn, const label fieldi ); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam } // End namespace fv // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* // |
|
CodedSource.C (5,679 bytes)
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation \\/ 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 "CodedSource.H" #include "fvMesh.H" #include "fvMatrices.H" #include "dynamicCode.H" #include "dynamicCodeContext.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template<class Type> void Foam::fv::CodedSource<Type>::prepare ( dynamicCode& dynCode, const dynamicCodeContext& context ) const { word sourceType(pTraits<Type>::typeName); // Set additional rewrite rules dynCode.setFilterVariable("typeName", name_); dynCode.setFilterVariable("TemplateType", sourceType); dynCode.setFilterVariable("SourceType", sourceType + "Source"); //dynCode.removeFilterVariable("code"); dynCode.setFilterVariable("codeCorrect", codeCorrect_); dynCode.setFilterVariable("codeAddSup", codeAddSup_); dynCode.setFilterVariable("codeSetValue", codeSetValue_); // compile filtered C template dynCode.addCompileFile("codedFvOptionTemplate.C"); // copy filtered H template dynCode.addCopyFile("codedFvOptionTemplate.H"); // debugging: make BC verbose // dynCode.setFilterVariable("verbose", "true"); // Info<<"compile " << name_ << " sha1: " // << context.sha1() << endl; // define Make/options dynCode.setMakeOptions ( "EXE_INC = -g \\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" "-I$(LIB_SRC)/meshTools/lnInclude \\\n" "-I$(LIB_SRC)/sampling/lnInclude \\\n" "-I$(LIB_SRC)/fvOptions/lnInclude \\\n" + context.options() + "\n\nLIB_LIBS = \\\n" + " -lmeshTools \\\n" + " -lfvOptions \\\n" + " -lsampling \\\n" + " -lfiniteVolume \\\n" + context.libs() ); } template<class Type> Foam::dlLibraryTable& Foam::fv::CodedSource<Type>::libs() const { return const_cast<Time&>(mesh_.time()).libs(); } template<class Type> Foam::string Foam::fv::CodedSource<Type>::description() const { return "fvOption:: " + name_; } template<class Type> void Foam::fv::CodedSource<Type>::clearRedirect() const { redirectFvOptionPtr_.clear(); } template<class Type> const Foam::dictionary& Foam::fv::CodedSource<Type>::codeDict() const { return coeffs_; } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type> Foam::fv::CodedSource<Type>::CodedSource ( const word& name, const word& modelType, const dictionary& dict, const fvMesh& mesh ) : cellSetOption(name, modelType, dict, mesh) { read(dict); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Type> Foam::fv::option& Foam::fv::CodedSource<Type>::redirectFvOption() const { if (!redirectFvOptionPtr_.valid()) { dictionary constructDict(dict_); constructDict.set("type", name_); redirectFvOptionPtr_ = option::New ( name_, constructDict, mesh_ ); } return redirectFvOptionPtr_(); } template<class Type> void Foam::fv::CodedSource<Type>::correct ( GeometricField<Type, fvPatchField, volMesh>& field ) { if (debug) { Info<< "CodedSource<"<< pTraits<Type>::typeName << ">::correct for source " << name_ << endl; } updateLibrary(name_); redirectFvOption().correct(field); } template<class Type> void Foam::fv::CodedSource<Type>::addSup ( fvMatrix<Type>& eqn, const label fieldi ) { if (debug) { Info<< "CodedSource<"<< pTraits<Type>::typeName << ">::addSup for source " << name_ << endl; } updateLibrary(name_); redirectFvOption().addSup(eqn, fieldi); } template<class Type> void Foam::fv::CodedSource<Type>::addSup ( const volScalarField& rho, fvMatrix<Type>& eqn, const label fieldi ) { if (debug) { Info<< "CodedSource<"<< pTraits<Type>::typeName << ">::addSup for source " << name_ << endl; } updateLibrary(name_); redirectFvOption().addSup(rho, eqn, fieldi); } template<class Type> void Foam::fv::CodedSource<Type>::constrain ( fvMatrix<Type>& eqn, const label fieldi ) { if (debug) { Info<< "CodedSource<"<< pTraits<Type>::typeName << ">::constrain for source " << name_ << endl; } updateLibrary(name_); redirectFvOption().constrain(eqn, fieldi); } // ************************************************************************* // |
|
CodedSource.H (5,942 bytes)
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation \\/ 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::fv::codedSource Description Constructs on-the-fly fvOption source The hook functions take the following arguments: codeCorrect ( GeometricField<Type, fvPatchField, volMesh>& field ) codeAddSup ( fvMatrix<Type}>& eqn, const label fieldi ) constrain ( fvMatrix<Type}>& eqn, const label fieldi ) where : field is the field in fieldNames eqn is the fvMatrix Usage Example usage in controlDict: \verbatim energySource { type scalarCodedSource; scalarCodedSourceCoeffs { selectionMode all; fields (h); name sourceTime; codeInclude #{ #}; codeCorrect #{ Pout<< "**codeCorrect**" << endl; #}; codeAddSup #{ const Time& time = mesh().time(); const scalarField& V = mesh_.V(); scalarField& heSource = eqn.source(); heSource -= 0.1*sqr(time.value())*V; #}; codeSetValue #{ Pout<< "**codeSetValue**" << endl; #}; // Dummy entry. Make dependent on above to trigger recompilation code #{ $codeInclude $codeCorrect $codeAddSup $codeSetValue #}; } sourceTimeCoeffs { // Dummy entry } } \endverbatim SourceFiles codedSource.C \*---------------------------------------------------------------------------*/ #ifndef CodedSource_H #define CodedSource_H #include "cellSetOption.H" #include "codedBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { namespace fv { /*---------------------------------------------------------------------------*\ Class codedSource Declaration \*---------------------------------------------------------------------------*/ template<class Type> class CodedSource : public cellSetOption, public codedBase { protected: // Protected data word name_; string codeCorrect_; string codeAddSup_; string codeSetValue_; //- Underlying functionObject mutable autoPtr<option> redirectFvOptionPtr_; // Protected Member Functions //- Get the loaded dynamic libraries virtual dlLibraryTable& libs() const; //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; // Return a description (type + name) for the output virtual string description() const; // Clear any redirected objects virtual void clearRedirect() const; // Get the dictionary to initialize the codeContext virtual const dictionary& codeDict() const; public: //- Runtime type information TypeName("coded"); // Constructors //- Construct from components CodedSource ( const word& name, const word& modelType, const dictionary& dict, const fvMesh& mesh ); // Member Functions //- Dynamically compiled fvOption option& redirectFvOption() const; // Evaluation //- Correct field virtual void correct ( GeometricField<Type, fvPatchField, volMesh>& ); //- Explicit and implicit matrix contributions virtual void addSup ( fvMatrix<Type>& eqn, const label fieldi ); //- Explicit and implicit matrix contributions // to compressible equation virtual void addSup ( const volScalarField& rho, fvMatrix<Type>& eqn, const label fieldi ); //- Set value virtual void constrain ( fvMatrix<Type>& eqn, const label fieldi ); // IO //- Read source dictionary virtual bool read(const dictionary& dict); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace fv } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository #include "CodedSource.C" #include "CodedSourceIO.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* // |
|
fvOptions (2,131 bytes)
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: dev | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "constant"; object fvOptions; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // energySource { type vectorCodedSource; //active yes; name sourceTime; vectorCodedSourceCoeffs { selectionMode all; //cellSet; //cellSet fields (U); codeInclude #{ #}; codeCorrect #{ Pout<< "**codeCorrect**" << endl; #}; codeAddSup #{ Pout<< "**codeAddSup**" << endl; const Time& time = mesh().time(); const scalarField& V = mesh_.V(); Pout<< "cells:" << cells() << endl; vectorField& heSource = eqn.source(); heSource -= sqr(time.value())*vector::one*V; #}; codeSetValue #{ Pout<< "**codeSetValue**" << endl; #}; // Dummy entry. Make dependent on above to trigger recompilation code #{ $codeInclude $codeCorrect $codeAddSup $codeSetValue #}; } sourceTimeCoeffs { $vectorCodedSourceCoeffs; } } // ************************************************************************* // |
|
I've uploaded the minimal changes for option 1. |
|
Resolved by commit 52323f8dd1db7a466e8a546996688acae84141b1 |
Date Modified | Username | Field | Change |
---|---|---|---|
2016-09-09 11:57 | MattijsJ | New Issue | |
2016-09-09 11:57 | MattijsJ | File Added: codedFvOptionTemplate.C | |
2016-09-09 11:58 | MattijsJ | File Added: codedFvOptionTemplate.H | |
2016-09-09 11:58 | MattijsJ | File Added: CodedSource.C | |
2016-09-09 11:59 | MattijsJ | File Added: CodedSource.H | |
2016-09-09 11:59 | MattijsJ | File Added: fvOptions | |
2016-09-09 12:00 | MattijsJ | Note Added: 0006851 | |
2016-09-09 12:34 | henry | Assigned To | => henry |
2016-09-09 12:34 | henry | Status | new => resolved |
2016-09-09 12:34 | henry | Resolution | open => fixed |
2016-09-09 12:34 | henry | Fixed in Version | => dev |
2016-09-09 12:34 | henry | Note Added: 0006852 |