ENH: function objects - enabled 'fields' entry to use patterns for some objects

This commit is contained in:
Andrew Heather
2017-11-07 17:33:09 +00:00
parent c1b7854cf7
commit ec9a7cc016
24 changed files with 1043 additions and 69 deletions

View File

@ -0,0 +1,85 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#include "fieldSelection.H"
#include "objectRegistry.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldSelection::fieldSelection
(
const objectRegistry& obr
)
:
HashSet<wordRe>(),
obr_(obr),
selection_()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldSelection::~fieldSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldSelection::read(const dictionary& dict)
{
dict.lookup("fields") >> *this;
return true;
}
bool Foam::functionObjects::fieldSelection::containsPattern() const
{
for (const wordRe& fieldName : *this)
{
if (fieldName.isPattern())
{
return true;
}
}
return false;
}
void Foam::functionObjects::fieldSelection::clearSelection()
{
selection_.clear();
}
bool Foam::functionObjects::fieldSelection::updateSelection()
{
return false;
}
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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
SourceFiles
fieldSelection.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldSelection_H
#define functionObjects_fieldSelection_H
#include "HashSet.H"
#include "wordRe.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class dictionary;
class objectRegistry;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldSelection Declaration
\*---------------------------------------------------------------------------*/
class fieldSelection
:
public HashSet<wordRe>
{
private:
// Private Member Functions
//- Disallow default bitwise copy construct
fieldSelection(const fieldSelection&) = delete;
protected:
// Protected member data
//- Reference to the database
const objectRegistry& obr_;
//- Current field selection
wordHashSet selection_;
// Protected Member Functions
//- Add registered objects of a given type
template<class Type>
void addRegistered(wordHashSet& set) const;
public:
//- Construct from object registry
fieldSelection(const objectRegistry& obr);
//- Destructor
virtual ~fieldSelection();
// Member Functions
//- Return the current field selection
const wordHashSet& selection() const
{
return selection_;
}
//- Return the current field selection
wordHashSet& selection()
{
return selection_;
}
//- 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 using current contents of obr_
virtual bool updateSelection();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldSelectionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#include "DynamicList.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fieldSelection::addRegistered
(
wordHashSet& set
) const
{
DynamicList<word> names;
for (const wordRe& name : *this)
{
names.append(obr_.names<Type>(name));
}
set.insert(names);
}
// ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#include "fileFieldSelection.H"
#include "objectRegistry.H"
#include "volMesh.H"
#include "fvPatchField.H"
#include "surfaceMesh.H"
#include "fvsPatchField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fileFieldSelection::fileFieldSelection
(
const objectRegistry& obr
)
:
fieldSelection(obr)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fileFieldSelection::updateSelection()
{
wordHashSet oldSet;
oldSet.swap(selection_);
addFileGeoFields<fvPatchField, volMesh>(selection_);
addFileGeoFields<fvsPatchField, surfaceMesh>(selection_);
return selection_ != oldSet;
}
// ************************************************************************* //

View File

@ -0,0 +1,115 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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::fileFieldSelection
Description
Helper class to manage file-based field selections
SourceFiles
fieldSelection.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fileFieldSelection_H
#define functionObjects_fileFieldSelection_H
#include "fieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class IOobjectList;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fileFieldSelection Declaration
\*---------------------------------------------------------------------------*/
class fileFieldSelection
:
public fieldSelection
{
private:
// Private Member Functions
//- Disallow default bitwise copy construct
fileFieldSelection(const fileFieldSelection&) = delete;
protected:
// Protected Member Functions
//- Add registered GeometricField types to selection
template<template<class> class PatchType, class MeshType>
void addFileGeoFields(wordHashSet& set) const;
//- Add objects of a given type
template<class Type>
void addFromFile
(
const IOobjectList& allFileObjects,
wordHashSet& set
) const;
public:
//- Construct from object registry
fileFieldSelection(const objectRegistry& obr);
//- Destructor
virtual ~fileFieldSelection();
// Member Functions
//- Update the selection
virtual bool updateSelection();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fileFieldSelectionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,77 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#include "IOobjectList.H"
#include "GeometricField.H"
#include "fvMesh.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fileFieldSelection::addFromFile
(
const IOobjectList& allFileObjects,
wordHashSet& set
) const
{
DynamicList<word> names;
for (const wordRe& fieldName : *this)
{
names.append(allFileObjects.names(Type::typeName, fieldName));
}
set.insert(names);
}
template<template<class> class PatchType, class MeshType>
void Foam::functionObjects::fileFieldSelection::addFileGeoFields
(
wordHashSet& set
) const
{
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
const IOobjectList allObjects(mesh, mesh.time().timeName());
addFromFile<GeometricField<scalar, PatchType, MeshType>>(allObjects, set);
addFromFile<GeometricField<vector, PatchType, MeshType>>(allObjects, set);
addFromFile<GeometricField<sphericalTensor, PatchType, MeshType>>
(
allObjects,
set
);
addFromFile<GeometricField<symmTensor, PatchType, MeshType>>
(
allObjects,
set
);
addFromFile<GeometricField<tensor, PatchType, MeshType>>(allObjects, set);
}
// ************************************************************************* //

View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#include "solverFieldSelection.H"
#include "fvMesh.H"
#include "volMesh.H"
#include "fvPatchField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::solverFieldSelection::solverFieldSelection
(
const objectRegistry& obr
)
:
volFieldSelection(obr)
{
if (!isA<fvMesh>(obr))
{
FatalErrorInFunction
<< "Registry must be of type " << fvMesh::typeName
<< abort(FatalError);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::solverFieldSelection::~solverFieldSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::solverFieldSelection::updateSelection()
{
wordHashSet oldSet;
oldSet.swap(selection_);
wordHashSet volFields;
addRegisteredGeoFields<fvPatchField, volMesh>(volFields);
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
const Foam::dictionary& solverDict = mesh.solverPerformanceDict();
for (const word& fieldName : volFields)
{
if (solverDict.found(fieldName))
{
selection_.insert(fieldName);
}
}
return selection_ != oldSet;
}
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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::volFieldSelection
Description
Helper class to manage volume field selections
SourceFiles
volFieldSelection.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_solverFieldSelection_H
#define functionObjects_solverFieldSelection_H
#include "volFieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class solverFieldSelection Declaration
\*---------------------------------------------------------------------------*/
class solverFieldSelection
:
public volFieldSelection
{
private:
// Private Member Functions
//- Disallow default bitwise copy construct
solverFieldSelection(const solverFieldSelection&) = delete;
public:
//- Construct from object registry
solverFieldSelection(const objectRegistry& obr);
//- Destructor
virtual ~solverFieldSelection();
// Member Functions
//- Update the selection using current contents of obr_
virtual bool updateSelection();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#include "volFieldSelection.H"
#include "volMesh.H"
#include "fvPatchField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::volFieldSelection::volFieldSelection
(
const objectRegistry& obr
)
:
fieldSelection(obr)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::volFieldSelection::~volFieldSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::volFieldSelection::updateSelection()
{
wordHashSet oldSet;
oldSet.swap(selection_);
addRegisteredGeoFields<fvPatchField, volMesh>(selection_);
return selection_ != oldSet;
}
// ************************************************************************* //

View File

@ -0,0 +1,104 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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::volFieldSelection
Description
Helper class to manage volume field selections
SourceFiles
volFieldSelection.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_volFieldSelection_H
#define functionObjects_volFieldSelection_H
#include "fieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class volFieldSelection Declaration
\*---------------------------------------------------------------------------*/
class volFieldSelection
:
public fieldSelection
{
private:
// Private Member Functions
//- Disallow default bitwise copy construct
volFieldSelection(const volFieldSelection&) = delete;
protected:
// Protected Member Functions
//- Add registered GeometricField types to selection
template<template<class> class PatchType, class MeshType>
void addRegisteredGeoFields(wordHashSet& set) const;
public:
//- Construct from object registry
volFieldSelection(const objectRegistry& obr);
//- Destructor
virtual ~volFieldSelection();
// Member Functions
//- Update the selection using current contents of obr_
virtual bool updateSelection();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "volFieldSelectionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 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/>.
\*---------------------------------------------------------------------------*/
#include "volFields.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<template<class> class PatchType, class MeshType>
void Foam::functionObjects::volFieldSelection::addRegisteredGeoFields
(
wordHashSet& set
) const
{
addRegistered<GeometricField<scalar, PatchType, MeshType>>(set);
addRegistered<GeometricField<vector, PatchType, MeshType>>(set);
addRegistered<GeometricField<sphericalTensor, PatchType, MeshType>>(set);
addRegistered<GeometricField<symmTensor, PatchType, MeshType>>(set);
addRegistered<GeometricField<tensor, PatchType, MeshType>>(set);
}
// ************************************************************************* //