mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Extended fieldSelection to include field components
This commit is contained in:
142
src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H
Normal file
142
src/finiteVolume/functionObjects/fieldSelection/fieldInfo.H
Normal file
@ -0,0 +1,142 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ 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::functionObjects::fieldInfo
|
||||
|
||||
Description
|
||||
Helper class to store a wordRe and label used by
|
||||
Foam::functionObjects::fieldSelection
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fieldInfo_H
|
||||
#define functionObjects_fieldInfo_H
|
||||
|
||||
#include "label.H"
|
||||
#include "wordRe.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldInfo Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldInfo;
|
||||
Istream& operator>>(Istream&, fieldInfo&);
|
||||
Ostream& operator<<(Ostream&, const fieldInfo&);
|
||||
|
||||
class fieldInfo
|
||||
{
|
||||
// Pivate data
|
||||
|
||||
//- Pattern for the field name
|
||||
wordRe name_;
|
||||
|
||||
//- Field component
|
||||
label component_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Null constructor
|
||||
fieldInfo()
|
||||
:
|
||||
name_(word::null),
|
||||
component_(-1)
|
||||
{}
|
||||
|
||||
|
||||
//- Construct from components
|
||||
fieldInfo(const wordRe& name, const label component = -1)
|
||||
:
|
||||
name_(name),
|
||||
component_(component)
|
||||
{}
|
||||
|
||||
//- Construct from stream
|
||||
fieldInfo(Istream& is)
|
||||
:
|
||||
name_(is),
|
||||
component_(readLabel(is))
|
||||
{}
|
||||
|
||||
|
||||
//- Destructor
|
||||
~fieldInfo() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
const wordRe& name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
label component() const
|
||||
{
|
||||
return component_;
|
||||
}
|
||||
|
||||
friend bool operator==(const fieldInfo& a, const fieldInfo& b)
|
||||
{
|
||||
return a.name_ == b.name_ && a.component_ == b.component_;
|
||||
}
|
||||
|
||||
friend bool operator!=(const fieldInfo& a, const fieldInfo& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>>(Istream& is, fieldInfo& fi)
|
||||
{
|
||||
is >> fi.name_ >> fi.component_;
|
||||
return is;
|
||||
}
|
||||
friend Ostream& operator<<(Ostream& os, const fieldInfo& fi)
|
||||
{
|
||||
os << fi.name_ << ' ' << fi.component_;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -31,36 +31,108 @@ License
|
||||
|
||||
Foam::functionObjects::fieldSelection::fieldSelection
|
||||
(
|
||||
const objectRegistry& obr
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents
|
||||
)
|
||||
:
|
||||
HashSet<wordRe>(),
|
||||
List<fieldInfo>(),
|
||||
obr_(obr),
|
||||
includeComponents_(includeComponents),
|
||||
selection_()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
bool Foam::functionObjects::fieldSelection::resetFieldFilters
|
||||
(
|
||||
const HashSet<wordRe>& names
|
||||
)
|
||||
{
|
||||
static word cmptStr(".component(");
|
||||
static string::size_type len(cmptStr.size());
|
||||
|
||||
Foam::functionObjects::fieldSelection::~fieldSelection()
|
||||
{}
|
||||
DynamicList<fieldInfo> nameAndComponent(names.size());
|
||||
|
||||
for (const wordRe& name : names)
|
||||
{
|
||||
string::size_type n = name.find(cmptStr);
|
||||
if (n != string::npos)
|
||||
{
|
||||
// Field should be written <field>.component(i)
|
||||
|
||||
if (!includeComponents_)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Component specification not allowed for " << name
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (name.isPattern())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot use \".component option\" in combination with "
|
||||
<< "wildcards for " << name
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
word baseName = name.substr(0, n);
|
||||
|
||||
// Extract the component - number between ()'s
|
||||
string::size_type closei = name.find(')', n);
|
||||
|
||||
if (closei == string::npos)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Invalid field component specification for "
|
||||
<< name << nl
|
||||
<< "Field should be expressed as <field>.component(i)"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
string::size_type cmptWidth = closei - n - len;
|
||||
|
||||
label component
|
||||
(
|
||||
readLabel(IStringStream(name.substr(n+len, cmptWidth))())
|
||||
);
|
||||
|
||||
nameAndComponent.append(fieldInfo(wordRe(baseName), component));
|
||||
}
|
||||
else
|
||||
{
|
||||
nameAndComponent.append(fieldInfo(name));
|
||||
}
|
||||
}
|
||||
|
||||
this->transfer(nameAndComponent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldSelection::resetFieldFilters
|
||||
(
|
||||
const wordRe& name
|
||||
)
|
||||
{
|
||||
return resetFieldFilters(HashSet<wordRe>({name}));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::fieldSelection::read(const dictionary& dict)
|
||||
{
|
||||
dict.readEntry("fields", *this);
|
||||
HashSet<wordRe> fields(dict.lookup("fields"));
|
||||
|
||||
return true;
|
||||
return resetFieldFilters(fields);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldSelection::containsPattern() const
|
||||
{
|
||||
for (const wordRe& fieldName : *this)
|
||||
for (const fieldInfo& fi : *this)
|
||||
{
|
||||
if (fieldName.isPattern())
|
||||
if (fi.name().isPattern())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -27,6 +27,11 @@ Class
|
||||
Description
|
||||
Helper class to manage field selections
|
||||
|
||||
The class holds a list of field name filters which are then applied to a
|
||||
set of field objects (in derived classes) from which the resulting set is
|
||||
available via the selection() function. This returns a list of
|
||||
(fieldName, component) objects, e.g. for U.component(0) this is (U, 0).
|
||||
|
||||
SourceFiles
|
||||
fieldSelection.C
|
||||
|
||||
@ -35,8 +40,9 @@ SourceFiles
|
||||
#ifndef functionObjects_fieldSelection_H
|
||||
#define functionObjects_fieldSelection_H
|
||||
|
||||
#include "fieldInfo.H"
|
||||
#include "DynamicList.H"
|
||||
#include "HashSet.H"
|
||||
#include "wordRe.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -55,7 +61,7 @@ namespace functionObjects
|
||||
|
||||
class fieldSelection
|
||||
:
|
||||
public HashSet<wordRe>
|
||||
public List<fieldInfo>
|
||||
{
|
||||
private:
|
||||
|
||||
@ -72,34 +78,49 @@ protected:
|
||||
//- Reference to the database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- Flag to indicate whether components are allowed
|
||||
const bool includeComponents_;
|
||||
|
||||
//- Current field selection
|
||||
wordHashSet selection_;
|
||||
List<fieldInfo> selection_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add registered objects of a given type
|
||||
template<class Type>
|
||||
void addRegistered(wordHashSet& set) const;
|
||||
void addRegistered(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
fieldSelection(const objectRegistry& obr);
|
||||
fieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fieldSelection();
|
||||
virtual ~fieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the cuurent filters
|
||||
inline HashSet<wordRe> filters() const;
|
||||
|
||||
inline const List<fieldInfo>& selection() const;
|
||||
|
||||
//- Return the current field selection
|
||||
const wordHashSet& selection() const
|
||||
{
|
||||
return selection_;
|
||||
}
|
||||
inline wordHashSet selectionNames() const;
|
||||
|
||||
//- Reset the field filters to the given field names
|
||||
virtual bool resetFieldFilters(const HashSet<wordRe>& names);
|
||||
|
||||
//- Reset the field filters to the given field name
|
||||
virtual bool resetFieldFilters(const wordRe& name);
|
||||
|
||||
//- Read the fieldSelection data from dictionary
|
||||
virtual bool read(const dictionary& dict);
|
||||
@ -122,6 +143,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "fieldSelectionI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fieldSelectionTemplates.C"
|
||||
#endif
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
inline Foam::HashSet<Foam::wordRe>
|
||||
Foam::functionObjects::fieldSelection::filters() const
|
||||
{
|
||||
HashSet<wordRe> f;
|
||||
for (const auto fieldInfo : *this)
|
||||
{
|
||||
f.insert(fieldInfo.name());
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
inline const Foam::List<Foam::functionObjects::fieldInfo>&
|
||||
Foam::functionObjects::fieldSelection::selection() const
|
||||
{
|
||||
return selection_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::wordHashSet
|
||||
Foam::functionObjects::fieldSelection::selectionNames() const
|
||||
{
|
||||
wordHashSet names;
|
||||
for (const fieldInfo& fi : *this)
|
||||
{
|
||||
names.insert(fi.name());
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,7 +23,6 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DynamicList.H"
|
||||
#include "objectRegistry.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
@ -31,12 +30,17 @@ License
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldSelection::addRegistered
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
for (const wordRe& name : *this)
|
||||
for (const fieldInfo& fi : *this)
|
||||
{
|
||||
set.insert(obr_.names<Type>(name));
|
||||
wordList names(obr_.names<Type>(fi.name()));
|
||||
for (const word& name : names)
|
||||
{
|
||||
set.append(fieldInfo(wordRe(name), fi.component()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -35,7 +35,7 @@ License
|
||||
|
||||
void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
@ -52,7 +52,7 @@ void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
|
||||
|
||||
void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
@ -71,16 +71,11 @@ void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
|
||||
|
||||
Foam::functionObjects::fileFieldSelection::fileFieldSelection
|
||||
(
|
||||
const objectRegistry& obr
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents
|
||||
)
|
||||
:
|
||||
fieldSelection(obr)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
|
||||
fieldSelection(obr, includeComponents)
|
||||
{}
|
||||
|
||||
|
||||
@ -88,19 +83,22 @@ Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
|
||||
|
||||
bool Foam::functionObjects::fileFieldSelection::updateSelection()
|
||||
{
|
||||
wordHashSet oldSet;
|
||||
oldSet.swap(selection_);
|
||||
List<fieldInfo> oldSet(std::move(selection_));
|
||||
|
||||
DynamicList<fieldInfo> newSelection(oldSet.size());
|
||||
|
||||
// Geometric fields
|
||||
addGeoFieldTypes<fvPatchField, volMesh>(selection_);
|
||||
addGeoFieldTypes<fvsPatchField, surfaceMesh>(selection_);
|
||||
addGeoFieldTypes<pointPatchField, pointMesh>(selection_);
|
||||
addGeoFieldTypes<fvPatchField, volMesh>(newSelection);
|
||||
addGeoFieldTypes<fvsPatchField, surfaceMesh>(newSelection);
|
||||
addGeoFieldTypes<pointPatchField, pointMesh>(newSelection);
|
||||
|
||||
// Internal fields
|
||||
addInternalFieldTypes(selection_);
|
||||
addInternalFieldTypes(newSelection);
|
||||
|
||||
// Uniform fields
|
||||
addUniformFieldTypes(selection_);
|
||||
addUniformFieldTypes(newSelection);
|
||||
|
||||
selection_.transfer(newSelection);
|
||||
|
||||
return selection_ != oldSet;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -69,31 +69,35 @@ protected:
|
||||
|
||||
//- Add registered GeometricField types to selection
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void addGeoFieldTypes(wordHashSet& set) const;
|
||||
void addGeoFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add registered Internal types to selection
|
||||
void addInternalFieldTypes(wordHashSet& set) const;
|
||||
void addInternalFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add registered uniform types to selection
|
||||
void addUniformFieldTypes(wordHashSet& set) const;
|
||||
void addUniformFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add objects of a given type
|
||||
template<class Type>
|
||||
void addFromFile
|
||||
(
|
||||
const IOobjectList& allFileObjects,
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
fileFieldSelection(const objectRegistry& obr);
|
||||
fileFieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fileFieldSelection();
|
||||
virtual ~fileFieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -33,12 +33,16 @@ template<class Type>
|
||||
void Foam::functionObjects::fileFieldSelection::addFromFile
|
||||
(
|
||||
const IOobjectList& allFileObjects,
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
for (const wordRe& fieldName : *this)
|
||||
for (const fieldInfo& fi : *this)
|
||||
{
|
||||
set.insert(allFileObjects.names(Type::typeName, fieldName));
|
||||
const wordList names(allFileObjects.names(Type::typeName, fi.name()));
|
||||
for (const word& name : names)
|
||||
{
|
||||
set.append(fieldInfo(wordRe(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +50,7 @@ void Foam::functionObjects::fileFieldSelection::addFromFile
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
|
||||
@ -32,10 +32,11 @@ License
|
||||
|
||||
Foam::functionObjects::solverFieldSelection::solverFieldSelection
|
||||
(
|
||||
const objectRegistry& obr
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents
|
||||
)
|
||||
:
|
||||
volFieldSelection(obr)
|
||||
volFieldSelection(obr, includeComponents)
|
||||
{
|
||||
if (!isA<fvMesh>(obr))
|
||||
{
|
||||
@ -46,34 +47,33 @@ Foam::functionObjects::solverFieldSelection::solverFieldSelection
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::solverFieldSelection::~solverFieldSelection()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::solverFieldSelection::updateSelection()
|
||||
{
|
||||
wordHashSet oldSet;
|
||||
oldSet.swap(selection_);
|
||||
List<fieldInfo> oldSet(std::move(selection_));
|
||||
|
||||
wordHashSet volFields;
|
||||
DynamicList<fieldInfo> volFields;
|
||||
addRegisteredGeoFields<fvPatchField, volMesh>(volFields);
|
||||
|
||||
DynamicList<fieldInfo> newSelection(oldSet.size());
|
||||
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
|
||||
const Foam::dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
|
||||
for (const word& fieldName : volFields)
|
||||
for (const fieldInfo& fi : volFields)
|
||||
{
|
||||
if (solverDict.found(fieldName))
|
||||
const wordRe& name = fi.name();
|
||||
|
||||
if (solverDict.found(name))
|
||||
{
|
||||
selection_.insert(fieldName);
|
||||
newSelection.append(fi);
|
||||
}
|
||||
}
|
||||
|
||||
selection_.transfer(newSelection);
|
||||
|
||||
return selection_ != oldSet;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -25,7 +25,7 @@ Class
|
||||
Foam::functionObjects::volFieldSelection
|
||||
|
||||
Description
|
||||
Helper class to manage volume field selections
|
||||
Helper class to manage solver field selections
|
||||
|
||||
SourceFiles
|
||||
volFieldSelection.C
|
||||
@ -63,11 +63,15 @@ private:
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
solverFieldSelection(const objectRegistry& obr);
|
||||
solverFieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~solverFieldSelection();
|
||||
virtual ~solverFieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2109 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -31,16 +31,11 @@ License
|
||||
|
||||
Foam::functionObjects::volFieldSelection::volFieldSelection
|
||||
(
|
||||
const objectRegistry& obr
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents
|
||||
)
|
||||
:
|
||||
fieldSelection(obr)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::volFieldSelection::~volFieldSelection()
|
||||
fieldSelection(obr, includeComponents)
|
||||
{}
|
||||
|
||||
|
||||
@ -48,11 +43,13 @@ Foam::functionObjects::volFieldSelection::~volFieldSelection()
|
||||
|
||||
bool Foam::functionObjects::volFieldSelection::updateSelection()
|
||||
{
|
||||
wordHashSet oldSet;
|
||||
List<fieldInfo> oldSet(std::move(selection_));
|
||||
|
||||
oldSet.swap(selection_);
|
||||
DynamicList<fieldInfo> newSet(oldSet.size());
|
||||
|
||||
addRegisteredGeoFields<fvPatchField, volMesh>(selection_);
|
||||
addRegisteredGeoFields<fvPatchField, volMesh>(newSet);
|
||||
|
||||
selection_.transfer(newSet);
|
||||
|
||||
return selection_ != oldSet;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -66,17 +66,21 @@ protected:
|
||||
|
||||
//- Add registered GeometricField types to selection
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void addRegisteredGeoFields(wordHashSet& set) const;
|
||||
void addRegisteredGeoFields(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
volFieldSelection(const objectRegistry& obr);
|
||||
volFieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~volFieldSelection();
|
||||
virtual ~volFieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -30,7 +30,7 @@ License
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void Foam::functionObjects::volFieldSelection::addRegisteredGeoFields
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
addRegistered<GeometricField<scalar, PatchType, MeshType>>(set);
|
||||
|
||||
@ -0,0 +1,161 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ 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::functionObjects::fieldSelection
|
||||
|
||||
Description
|
||||
Helper class to manage field selections
|
||||
|
||||
The class holds a list of field name filters which are then applied to a
|
||||
set of field objects (in derived classes) from which the resulting set is
|
||||
available via the selection() function. This returns a list of
|
||||
(fieldName, component) objects, e.g. for U.component(0) this is (U, 0).
|
||||
|
||||
SourceFiles
|
||||
fieldSelection.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fieldSelection_H
|
||||
#define functionObjects_fieldSelection_H
|
||||
|
||||
#include "fieldInfo.H"
|
||||
#include "DynamicList.H"
|
||||
#include "HashSet.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class dictionary;
|
||||
class objectRegistry;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldSelection Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldSelection
|
||||
:
|
||||
public List<fieldInfo>
|
||||
{
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy construct
|
||||
fieldSelection(const fieldSelection&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected member data
|
||||
|
||||
//- Reference to the database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- Flag to indicate whether components are allowed
|
||||
const bool includeComponents_;
|
||||
|
||||
//- Current field selection
|
||||
List<fieldInfo> selection_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add registered objects of a given type
|
||||
template<class Type>
|
||||
void addRegistered(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
fieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the cuurent filters
|
||||
inline HashSet<wordRe> filters() const;
|
||||
|
||||
inline const List<fieldInfo>& selection() const;
|
||||
|
||||
//- Return the current field selection
|
||||
inline wordHashSet selectionNames() const;
|
||||
|
||||
//- Reset the field filters to the given field names
|
||||
virtual bool resetFieldFilters(const HashSet<wordRe>& names);
|
||||
|
||||
//- Reset the field filters to the given field name
|
||||
virtual bool resetFieldFilters(const wordRe& name);
|
||||
|
||||
//- Read the fieldSelection data from dictionary
|
||||
virtual bool read(const dictionary& dict);
|
||||
|
||||
//- Return whether the field names contain a pattern
|
||||
virtual bool containsPattern() const;
|
||||
|
||||
//- Clear the current selection
|
||||
virtual void clearSelection();
|
||||
|
||||
//- Update the selection
|
||||
virtual bool updateSelection();
|
||||
|
||||
//- Check that all requested fielda have been found
|
||||
virtual bool checkSelection();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "fieldSelectionI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fieldSelectionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user