/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2023-2026 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 . \*---------------------------------------------------------------------------*/ #include "fvFieldSource.H" #include "fvSource.H" #include "fvMesh.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::fvFieldSource::fvFieldSource ( const DimensionedField& iF ) : libs_(fileNameList::null()), internalField_(iF) {} template Foam::fvFieldSource::fvFieldSource ( const DimensionedField& iF, const dictionary& dict ) : libs_(dict.lookupOrDefault("libs", fileNameList::null())), internalField_(iF) {} template Foam::fvFieldSource::fvFieldSource ( const fvFieldSource& field, const DimensionedField& iF ) : libs_(field.libs_), internalField_(iF) {} // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // template Foam::autoPtr> Foam::fvFieldSource::New ( const word& fieldSourceType, const DimensionedField& iF ) { typename nullConstructorTable::iterator cstrIter = nullConstructorTablePtr_->find(fieldSourceType); if (cstrIter == nullConstructorTablePtr_->end()) { FatalErrorInFunction << "Unknown null-constructable fieldSource type " << fieldSourceType << nl << nl << "Valid fieldSource types are :" << endl << nullConstructorTablePtr_->sortedToc() << exit(FatalIOError); } return cstrIter()(iF); } template Foam::autoPtr> Foam::fvFieldSource::New ( const DimensionedField& iF, const dictionary& dict ) { const word fieldSourceType(dict.lookup("type")); libs.open(dict, "libs", dictionaryConstructorTablePtr_); typename dictionaryConstructorTable::iterator cstrIter = dictionaryConstructorTablePtr_->find(fieldSourceType); if (cstrIter == dictionaryConstructorTablePtr_->end()) { if (!disallowGenericFvFieldSource) { cstrIter = dictionaryConstructorTablePtr_->find("generic"); } if (cstrIter == dictionaryConstructorTablePtr_->end()) { FatalIOErrorInFunction(dict) << "Unknown fieldSource type " << fieldSourceType << " for model " << dict.dictName() << nl << nl << "Valid fieldSource types are :" << endl << dictionaryConstructorTablePtr_->sortedToc() << exit(FatalIOError); } } return cstrIter()(iF, dict); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template Foam::fvFieldSource::~fvFieldSource() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template const Foam::objectRegistry& Foam::fvFieldSource::db() const { return internalField_.mesh(); } template const Foam::Time& Foam::fvFieldSource::time() const { return internalField_.mesh().time(); } template const Foam::DimensionedField& Foam::fvFieldSource::internalField() const { return internalField_; } template Foam::tmp> Foam::fvFieldSource::sourceValue ( const fvSource& model, const scalarField& source, const labelUList& cells ) const { FatalErrorInFunction << "Condition of type " << type() << " cannot be used for source " << model.name() << " of field " << internalField().name() << " in file " << internalField().objectPath() << " as it is not " << "defined for cell sets. It can only be used for sources that " << "span the entire mesh." << exit(FatalError); return tmp>(nullptr); } template Foam::tmp Foam::fvFieldSource::internalCoeff ( const fvSource& model, const scalarField& source, const labelUList& cells ) const { FatalErrorInFunction << "Condition of type " << type() << " cannot be used for source " << model.name() << " of field " << internalField().name() << " in file " << internalField().objectPath() << " as it is not " << "defined for cell sets. It can only be used for sources that " << "span the entire mesh." << exit(FatalError); return tmp(nullptr); } template Foam::tmp> Foam::fvFieldSource::sourceTerm ( const fvSource& model, const DimensionedField& source ) const { return source *(1 - internalCoeff(model, source)) *sourceValue(model, source); } template Foam::tmp> Foam::fvFieldSource::sourceTerm ( const fvSource& model, const scalarField& source, const labelUList& cells ) const { return source *(1 - internalCoeff(model, source, cells)) *sourceValue(model, source, cells); } template Foam::tmp> Foam::fvFieldSource::term ( const fvSource& model, const DimensionedField& source ) const { return sourceTerm(model, source) + source *internalCoeff(model, source) *internalField(); } template Foam::tmp> Foam::fvFieldSource::term ( const fvSource& model, const scalarField& source, const labelUList& cells ) const { return sourceTerm(model, source, cells) + source *internalCoeff(model, source, cells) *Field(internalField(), cells); } template Foam::tmp> Foam::fvFieldSource::value ( const fvSource& model, const DimensionedField& source ) const { return (1 - internalCoeff(model, source)) *sourceValue(model, source); + internalCoeff(model, source) *internalField(); } template Foam::tmp> Foam::fvFieldSource::value ( const fvSource& model, const scalarField& source, const labelUList& cells ) const { return (1 - internalCoeff(model, source, cells)) *sourceValue(model, source, cells); + internalCoeff(model, source, cells) *Field(internalField(), cells); } template template const Foam::fvFieldSource& Foam::fvFieldSource::fieldSource ( const word& name, const fvSource& model ) const { const VolField& vf = db().template lookupObject>(name); return vf.sources()[model.name()]; } template template Foam::tmp> Foam::fvFieldSource::value ( const word& name, const fvSource& model, const DimensionedField& source ) const { return fieldSource(name, model).value(model, source); } template template Foam::tmp> Foam::fvFieldSource::value ( const word& name, const fvSource& model, const scalarField& source, const labelUList& cells ) const { return fieldSource(name, model).value(model, source, cells); } template void Foam::fvFieldSource::write(Ostream& os) const { writeEntry(os, "type", type()); if (libs_.size()) { writeEntry(os, "libs", libs_); } } // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template Foam::Ostream& Foam::operator<<(Ostream& os, const fvFieldSource& ptf) { ptf.write(os); os.check("Ostream& operator<<(Ostream&, const fvFieldSource&"); return os; } // ************************************************************************* //