/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 . \*---------------------------------------------------------------------------*/ #include "codedFixedValueFvPatchField.H" #include "addToRunTimeSelectionTable.H" #include "fvPatchFieldMapper.H" #include "volFields.H" #include "dynamicCode.H" #include "dynamicCodeContext.H" #include "stringOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template const Foam::word Foam::codedFixedValueFvPatchField::codeTemplateC = "fixedValueFvPatchFieldTemplate.C"; template const Foam::word Foam::codedFixedValueFvPatchField::codeTemplateH = "fixedValueFvPatchFieldTemplate.H"; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // template void Foam::codedFixedValueFvPatchField::setFieldTemplates ( dynamicCode& dynCode ) { word fieldType(pTraits::typeName); // template type for fvPatchField dynCode.setFilterVariable("TemplateType", fieldType); // Name for fvPatchField - eg, ScalarField, VectorField, ... fieldType[0] = toupper(fieldType[0]); dynCode.setFilterVariable("FieldType", fieldType + "Field"); } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template const Foam::IOdictionary& Foam::codedFixedValueFvPatchField::dict() const { const objectRegistry& obr = this->db(); if (obr.foundObject("codeDict")) { return obr.lookupObject("codeDict"); } else { return obr.store ( new IOdictionary ( IOobject ( "codeDict", this->db().time().system(), this->db(), IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ) ); } } template Foam::dlLibraryTable& Foam::codedFixedValueFvPatchField::libs() const { return const_cast(this->db().time().libs()); } template void Foam::codedFixedValueFvPatchField::prepare ( dynamicCode& dynCode, const dynamicCodeContext& context ) const { // take no chances - typeName must be identical to redirectType_ dynCode.setFilterVariable("typeName", redirectType_); // set TemplateType and FieldType filter variables // (for fvPatchField) setFieldTemplates(dynCode); // compile filtered C template dynCode.addCompileFile(codeTemplateC); // copy filtered H template dynCode.addCopyFile(codeTemplateH); // debugging: make BC verbose // dynCode.setFilterVariable("verbose", "true"); // Info<<"compile " << redirectType_ << " sha1: " // << context.sha1() << endl; // define Make/options dynCode.setMakeOptions ( "EXE_INC = -g \\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" + context.options() + "\n\nLIB_LIBS = \\\n" + " -lOpenFOAM \\\n" + " -lfiniteVolume \\\n" + context.libs() ); } template const Foam::dictionary& Foam::codedFixedValueFvPatchField::codeDict() const { // use system/codeDict or in-line return ( dict_.found("code") ? dict_ : this->dict().subDict(redirectType_) ); } template Foam::string Foam::codedFixedValueFvPatchField::description() const { return "patch " + this->patch().name() + " on field " + this->dimensionedInternalField().name(); } template void Foam::codedFixedValueFvPatchField::clearRedirect() const { // remove instantiation of fvPatchField provided by library redirectPatchFieldPtr_.clear(); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::codedFixedValueFvPatchField::codedFixedValueFvPatchField ( const fvPatch& p, const DimensionedField& iF ) : fixedValueFvPatchField(p, iF), codedBase(), redirectPatchFieldPtr_() {} template Foam::codedFixedValueFvPatchField::codedFixedValueFvPatchField ( const codedFixedValueFvPatchField& ptf, const fvPatch& p, const DimensionedField& iF, const fvPatchFieldMapper& mapper ) : fixedValueFvPatchField(ptf, p, iF, mapper), codedBase(), dict_(ptf.dict_), redirectType_(ptf.redirectType_), redirectPatchFieldPtr_() {} template Foam::codedFixedValueFvPatchField::codedFixedValueFvPatchField ( const fvPatch& p, const DimensionedField& iF, const dictionary& dict ) : fixedValueFvPatchField(p, iF, dict), codedBase(), dict_(dict), redirectType_(dict.lookup("redirectType")), redirectPatchFieldPtr_() { updateLibrary(redirectType_); } template Foam::codedFixedValueFvPatchField::codedFixedValueFvPatchField ( const codedFixedValueFvPatchField& ptf ) : fixedValueFvPatchField(ptf), codedBase(), dict_(ptf.dict_), redirectType_(ptf.redirectType_), redirectPatchFieldPtr_() {} template Foam::codedFixedValueFvPatchField::codedFixedValueFvPatchField ( const codedFixedValueFvPatchField& ptf, const DimensionedField& iF ) : fixedValueFvPatchField(ptf, iF), codedBase(), dict_(ptf.dict_), redirectType_(ptf.redirectType_), redirectPatchFieldPtr_() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template const Foam::fvPatchField& Foam::codedFixedValueFvPatchField::redirectPatchField() const { if (!redirectPatchFieldPtr_.valid()) { // Construct a patch // Make sure to construct the patchfield with up-to-date value OStringStream os; os.writeKeyword("type") << redirectType_ << token::END_STATEMENT << nl; static_cast&>(*this).writeEntry("value", os); IStringStream is(os.str()); dictionary dict(is); redirectPatchFieldPtr_.set ( fvPatchField::New ( this->patch(), this->dimensionedInternalField(), dict ).ptr() ); } return redirectPatchFieldPtr_(); } template void Foam::codedFixedValueFvPatchField::updateCoeffs() { if (this->updated()) { return; } // Make sure library containing user-defined fvPatchField is up-to-date updateLibrary(redirectType_); const fvPatchField& fvp = redirectPatchField(); const_cast&>(fvp).updateCoeffs(); // Copy through value this->operator==(fvp); fixedValueFvPatchField::updateCoeffs(); } template void Foam::codedFixedValueFvPatchField::evaluate ( const Pstream::commsTypes commsType ) { // Make sure library containing user-defined fvPatchField is up-to-date updateLibrary(redirectType_); const fvPatchField& fvp = redirectPatchField(); const_cast&>(fvp).evaluate(commsType); fixedValueFvPatchField::evaluate(commsType); } template void Foam::codedFixedValueFvPatchField::write(Ostream& os) const { fixedValueFvPatchField::write(os); os.writeKeyword("redirectType") << redirectType_ << token::END_STATEMENT << nl; codedBase::writeCodeDict(os, dict_); } // ************************************************************************* //