.. _program_listing_file_samplers_Sampler_Sampler.C: Program Listing for File Sampler.C ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``samplers/Sampler/Sampler.C``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /*---------------------------------------------------------------------------* \ License This file is part of libWallModelledLES. libWallModelledLES 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. libWallModelledLES 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 libWallModelledLES. If not, see . \*---------------------------------------------------------------------------*/ #include "Sampler.H" #include "meshSearch.H" #include "fvPatchFieldMapper.H" #include "volFields.H" #include "wallFvPatch.H" #include "objectRegistry.H" #include "IOField.H" #include "SampledField.H" #include "codeRules.H" #include "patchDistMethod.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #if !defined(DOXYGEN_SHOULD_SKIP_THIS) namespace Foam { defineTypeNameAndDebug(Sampler, 0); defineRunTimeSelectionTable(Sampler, SamplerRTSTable); } #endif // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // Foam::autoPtr Foam::Sampler::New ( const word & samplerName, const fvPatch & p, scalar averagingTime, const word interpolationType, const word cellFinderType, const word lengthScaleType, bool hIsIndex, bool excludeWallAdjacent ) { auto cstrIter = SamplerRTSTableConstructorTablePtr_->find(samplerName); if (cstrIter == SamplerRTSTableConstructorTablePtr_->end()) { FatalErrorIn ( "Sampler::New(const word&, const fvPatch & p, scalar averagingTime" ) << "Unknown Sampler type " << samplerName << nl << nl << "Valid Sampler types are :" << nl << SamplerRTSTableConstructorTablePtr_->sortedToc() << exit(FatalError); } return cstrIter() ( samplerName, p, averagingTime, interpolationType, cellFinderType, lengthScaleType, hIsIndex, excludeWallAdjacent ); } Foam::autoPtr Foam::Sampler::New ( const dictionary & dict, const fvPatch & p ) { word samplerName = dict.lookupOrDefault("type", "SingleCellSampler"); scalar averagingTime = dict.lookupOrDefault("averagingTime", 0.0); word interpolationType = dict.lookupOrDefault("interpolationType", "cell"); word cellFinderType = dict.lookupOrDefault("sampler", "Tree"); word lengthScaleType = dict.lookupOrDefault("lengthScale", "CubeRootVol"); bool hIsIndex = dict.lookupOrDefault("hIsIndex", false); bool excludeWallAdjacent = dict.lookupOrDefault("excludeWallAdjacent", false); return Foam::Sampler::New ( samplerName, p, averagingTime, interpolationType, cellFinderType, lengthScaleType, hIsIndex, excludeWallAdjacent ); } // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::Sampler::createFields() { bool foundhSampler = mesh_.foundObject("hSampler"); word hName; // Grab h for the current patch if (foundhSampler) { hName = "hSampler"; } else { hName = "h"; } const volScalarField & h = mesh_.lookupObject (hName); // Field that marks cells that are used for sampling if (!mesh_.thisDb().found("samplingCells")) { if (debug) { Info<< "Sampler: Creating samplingCells field" << nl; } mesh_.thisDb().store ( new volScalarField ( IOobject ( "samplingCells", mesh_.time().timeName(), mesh_, IOobject::NO_READ, IOobject::AUTO_WRITE ), patch().boundaryMesh().mesh(), dimensionedScalar("samplingCells", dimless, -1), h.boundaryField().types() ) ); } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::Sampler::Sampler ( const fvPatch & p, scalar averagingTime, const word interpolationType, const word cellFinderType, const word lengthScaleType, bool hIsIndex, bool excludeWallAdjacent ) : patch_(p), averagingTime_(averagingTime), mesh_(patch_.boundaryMesh().mesh()), sampledFields_(0), interpolationType_(interpolationType), cellFinderType_(cellFinderType), lengthScaleType_(lengthScaleType), hIsIndex_(hIsIndex), excludeWallAdjacent_(excludeWallAdjacent), skipSamplingSetup_ ( static_cast ( Switch::find ( Foam::getEnv("LIBWMLES_SKIP_SAMPLING_SETUP") ) ) ) { if (debug) { Info << "Sampler: Constructing from patch and avrg time" << nl; } if (!mesh_.foundObject("wallModelSampling")) { objectRegistry * subObr = new objectRegistry ( IOobject ( "wallModelSampling", mesh_.time().constant(), mesh_, IOobject::NO_READ, IOobject::NO_WRITE ) ); subObr->store(); } if ( !mesh_.subRegistry ( "wallModelSampling" ).foundObject(patch_.name()) ) { objectRegistry * subObr = new objectRegistry ( IOobject ( patch_.name(), mesh_.time().constant(), mesh_.subRegistry("wallModelSampling"), IOobject::NO_READ, IOobject::NO_WRITE ) ); subObr->store(); } if (!skipSamplingSetup_) { createFields(); } else { if (debug) { Info << "Sampler: Skipping sampling setup because " << "LIBWMLES_SKIP_SAMPLING_SETUP is enabled" << nl; } } } Foam::Sampler::Sampler ( const word & samplerName, const fvPatch & p, scalar averagingTime, const word interpolationType, const word cellFinderType, const word lengthScaleType, bool hIsIndex, bool excludeWallAdjacent ) : Sampler ( p, averagingTime, interpolationType, cellFinderType, lengthScaleType, hIsIndex, excludeWallAdjacent ) { } Foam::Sampler::Sampler(const Sampler & copy) : patch_(copy.patch_), averagingTime_(copy.averagingTime_), mesh_(copy.mesh_), sampledFields_(copy.sampledFields_), interpolationType_(copy.interpolationType_), cellFinderType_(copy.cellFinderType_), lengthScaleType_(copy.lengthScaleType_), hIsIndex_(copy.hIsIndex_), excludeWallAdjacent_(copy.excludeWallAdjacent_), skipSamplingSetup_(copy.skipSamplingSetup_) { if (debug) { Info << "Sampler: Running copy constructor" << nl; } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::Sampler::~Sampler() { if (debug) { Info << "Sampler: Running destructor" << nl; } } void Foam::Sampler::addField(SampledField * field) { sampledFields_.setSize(sampledFields_.size() + 1); sampledFields_.set(sampledFields_.size() -1, field); } void Foam::Sampler::recomputeFields() const { if (skipSamplingSetup_) { FatalErrorInFunction << "Sampling setup was skipped because " << "LIBWMLES_SKIP_SAMPLING_SETUP is enabled. " << "Unset it before running a solver that evaluates wall models." << exit(FatalError); } forAll(sampledFields_, i) { sampledFields_[i].recompute(); } } void Foam::Sampler::write(Ostream & os) const { os.writeKeyword("interpolationType") << interpolationType_ << token::END_STATEMENT << endl; os.writeKeyword("sampler") << cellFinderType_ << token::END_STATEMENT << endl; os.writeKeyword("lengthScale") << lengthScaleType_ << token::END_STATEMENT << endl; os.writeKeyword("hIsIndex") << hIsIndex_ << token::END_STATEMENT << endl; os.writeKeyword("excludeWallAdjacent") << excludeWallAdjacent_ << token::END_STATEMENT << endl; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //