/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-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 "streamlines.H" #include "streamlinesCloud.H" #include "sampledSet.H" #include "globalIndex.H" #include "cellPoint_interpolation.H" #include "PatchTools.H" #include "writeFile.H" #include "polyTopoChangeMap.H" #include "polyMeshMap.H" #include "polyDistributionMap.H" #include "OSspecific.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { namespace functionObjects { defineTypeNameAndDebug(streamlines, 0); addToRunTimeSelectionTable(functionObject, streamlines, dictionary); } } const Foam::NamedEnum Foam::functionObjects::streamlines::trackDirectionNames_ { "forward", "backward", "both" }; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::streamlines::streamlines ( const word& name, const Time& runTime, const dictionary& dict ) : fvMeshFunctionObject(name, runTime, dict), nSubCycle_(0) { read(dict); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::functionObjects::streamlines::~streamlines() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionObjects::streamlines::read(const dictionary& dict) { dict.lookup("fields") >> fields_; UName_ = dict.lookupOrDefault("U", word("U")); writeAge_ = dict.lookupOrDefault("writeAge", true); trackDirection_ = trackDirectionNames_[word(dict.lookup("direction"))]; trackOutside_ = dict.lookupOrDefault("outside", false); dict.lookup("lifeTime") >> lifeTime_; if (lifeTime_ < 1) { FatalErrorInFunction << "Illegal value " << lifeTime_ << " for lifeTime" << exit(FatalError); } bool subCycling = dict.found("nSubCycle"); bool fixedLength = dict.found("trackLength"); if (subCycling && fixedLength) { FatalIOErrorInFunction(dict) << "Cannot both specify automatic time stepping (through '" << "nSubCycle' specification) and fixed track length (through '" << "trackLength')" << exit(FatalIOError); } if (subCycling) { nSubCycle_ = max(dict.lookup("nSubCycle"), 1); trackLength_ = vGreat; Info<< indent << "automatic track length specified through" << " number of sub cycles : " << nSubCycle_ << endl; } else { nSubCycle_ = 1; dict.lookup("trackLength") >> trackLength_; Info<< indent << " fixed track length specified : " << trackLength_ << endl; } interpolationScheme_ = dict.lookupOrDefault ( "interpolationScheme", interpolations::cellPoint::typeName ); cloudName_ = dict.lookupOrDefault("cloudName", "streamlines"); sampledSetPtr_ = sampledSet::New ( "seedSampleSet", mesh_, dict.subDict("seedSampleSet") ); formatterPtr_ = setWriter::New(dict.lookup("setFormat"), dict); return true; } Foam::wordList Foam::functionObjects::streamlines::fields() const { wordList allFields(fields_); allFields.append(UName_); return allFields; } bool Foam::functionObjects::streamlines::execute() { return true; } bool Foam::functionObjects::streamlines::write() { Info<< indent << type() << " " << name() << " write:" << nl; // Create list of available fields wordList fieldNames; forAll(fields_, fieldi) { if ( false #define FoundTypeField(Type, nullArg) \ || foundObject>(fields_[fieldi]) FOR_ALL_FIELD_TYPES(FoundTypeField) #undef FoundTypeField ) { fieldNames.append(fields_[fieldi]); } else { cannotFindObject(fields_[fieldi]); } } // Lookup fields and construct interpolators #define DeclareTypeInterpolator(Type, nullArg) \ PtrList> Type##Interp(fieldNames.size()); FOR_ALL_FIELD_TYPES(DeclareTypeInterpolator); #undef DeclareTypeInterpolator forAll(fieldNames, fieldi) { #define ConstructTypeInterpolator(Type, nullArg) \ if (mesh_.foundObject>(fieldNames[fieldi])) \ { \ Type##Interp.set \ ( \ fieldi, \ interpolation::New \ ( \ interpolationScheme_, \ mesh_.lookupObject>(fieldNames[fieldi]) \ ) \ ); \ } FOR_ALL_FIELD_TYPES(ConstructTypeInterpolator); #undef ConstructTypeInterpolator } // Create a velocity interpolator if it is not already available const label UIndex = findIndex(fieldNames, UName_); tmpNrc> UInterp(nullptr); if (UIndex == -1) { UInterp = tmpNrc> ( interpolation::New ( interpolationScheme_, mesh_.lookupObject(UName_) ).ptr() ); } // Get the mesh searching engine const meshSearch& searchEngine = meshSearch::New(mesh_); // Do tracking to create sampled data DynamicField allPositions; DynamicField