mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: avoid redundant IOobjectList use
- areaWrite and fileFieldSelection
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,45 +27,98 @@ License
|
||||
|
||||
#include "fileFieldSelection.H"
|
||||
#include "objectRegistry.H"
|
||||
#include "IOobjectList.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volMesh.H"
|
||||
#include "fvPatchField.H"
|
||||
#include "surfaceMesh.H"
|
||||
#include "fvsPatchField.H"
|
||||
#include "pointMesh.H"
|
||||
#include "pointPatchField.H"
|
||||
#include "GeometricField.H"
|
||||
#include "UniformDimensionedField.H"
|
||||
|
||||
void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fileFieldSelection::addFromFile
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
for (const fieldInfo& fi : *this)
|
||||
{
|
||||
const wordList names(objects.sortedNames<Type>(fi.name()));
|
||||
|
||||
const IOobjectList allObjects(mesh, mesh.time().timeName());
|
||||
if (names.size())
|
||||
{
|
||||
for (const word& name : names)
|
||||
{
|
||||
set.append(fieldInfo(wordRe(name)));
|
||||
}
|
||||
|
||||
addFromFile<DimensionedField<scalar, volMesh>>(allObjects, set);
|
||||
addFromFile<DimensionedField<vector, volMesh>>(allObjects, set);
|
||||
addFromFile<DimensionedField<sphericalTensor, volMesh>>(allObjects, set);
|
||||
addFromFile<DimensionedField<symmTensor, volMesh>>(allObjects, set);
|
||||
addFromFile<DimensionedField<tensor, volMesh>>(allObjects, set);
|
||||
fi.found() = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
#undef doLocalCode
|
||||
#define doLocalCode(DataType) \
|
||||
addFromFile<GeometricField<DataType, PatchType, MeshType>>(objects, set);
|
||||
|
||||
doLocalCode(scalar);
|
||||
doLocalCode(vector);
|
||||
doLocalCode(sphericalTensor);
|
||||
doLocalCode(symmTensor);
|
||||
doLocalCode(tensor);
|
||||
#undef doLocalCode
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
#undef doLocalCode
|
||||
#define doLocalCode(DataType) \
|
||||
addFromFile<DimensionedField<DataType, volMesh>>(objects, set);
|
||||
|
||||
doLocalCode(scalar);
|
||||
doLocalCode(vector);
|
||||
doLocalCode(sphericalTensor);
|
||||
doLocalCode(symmTensor);
|
||||
doLocalCode(tensor);
|
||||
#undef doLocalCode
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
#undef doLocalCode
|
||||
#define doLocalCode(DataType) \
|
||||
addFromFile<UniformDimensionedField<DataType>>(objects, set);
|
||||
|
||||
const IOobjectList allObjects(mesh, mesh.time().timeName());
|
||||
|
||||
addFromFile<UniformDimensionedField<scalar>>(allObjects, set);
|
||||
addFromFile<UniformDimensionedField<vector>>(allObjects, set);
|
||||
addFromFile<UniformDimensionedField<sphericalTensor>>(allObjects, set);
|
||||
addFromFile<UniformDimensionedField<symmTensor>>(allObjects, set);
|
||||
addFromFile<UniformDimensionedField<tensor>>(allObjects, set);
|
||||
doLocalCode(scalar);
|
||||
doLocalCode(vector);
|
||||
doLocalCode(sphericalTensor);
|
||||
doLocalCode(symmTensor);
|
||||
doLocalCode(tensor);
|
||||
#undef doLocalCode
|
||||
}
|
||||
|
||||
|
||||
@ -85,20 +138,23 @@ Foam::functionObjects::fileFieldSelection::fileFieldSelection
|
||||
|
||||
bool Foam::functionObjects::fileFieldSelection::updateSelection()
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
const IOobjectList objects(mesh, mesh.time().timeName());
|
||||
|
||||
List<fieldInfo> oldSet(std::move(selection_));
|
||||
|
||||
DynamicList<fieldInfo> newSelection(oldSet.size());
|
||||
|
||||
// Geometric fields
|
||||
addGeoFieldTypes<fvPatchField, volMesh>(newSelection);
|
||||
addGeoFieldTypes<fvsPatchField, surfaceMesh>(newSelection);
|
||||
addGeoFieldTypes<pointPatchField, pointMesh>(newSelection);
|
||||
addGeoFieldTypes<fvPatchField, volMesh>(objects, newSelection);
|
||||
addGeoFieldTypes<fvsPatchField, surfaceMesh>(objects, newSelection);
|
||||
addGeoFieldTypes<pointPatchField, pointMesh>(objects, newSelection);
|
||||
|
||||
// Internal fields
|
||||
addInternalFieldTypes(newSelection);
|
||||
addInternalFieldTypes(objects, newSelection);
|
||||
|
||||
// Uniform fields
|
||||
addUniformFieldTypes(newSelection);
|
||||
addUniformFieldTypes(objects, newSelection);
|
||||
|
||||
selection_.transfer(newSelection);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -44,6 +44,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
class IOobjectList;
|
||||
|
||||
namespace functionObjects
|
||||
@ -57,41 +58,49 @@ class fileFieldSelection
|
||||
:
|
||||
public fieldSelection
|
||||
{
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy construct
|
||||
fileFieldSelection(const fileFieldSelection&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add registered GeometricField types to selection
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void addGeoFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add registered Internal types to selection
|
||||
void addInternalFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add registered uniform types to selection
|
||||
void addUniformFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add objects of a given type
|
||||
template<class Type>
|
||||
void addFromFile
|
||||
(
|
||||
const IOobjectList& allFileObjects,
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const;
|
||||
|
||||
//- Add registered GeometricField types to selection
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void addGeoFieldTypes
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const;
|
||||
|
||||
//- Add registered Internal types to selection
|
||||
void addInternalFieldTypes
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const;
|
||||
|
||||
//- Add registered uniform types to selection
|
||||
void addUniformFieldTypes
|
||||
(
|
||||
const IOobjectList& objects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const;
|
||||
|
||||
|
||||
//- No copy construct
|
||||
fileFieldSelection(const fileFieldSelection&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from object registry
|
||||
fileFieldSelection
|
||||
explicit fileFieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
@ -116,12 +125,6 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fileFieldSelectionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fileFieldSelection::addFromFile
|
||||
(
|
||||
const IOobjectList& allFileObjects,
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
for (const fieldInfo& fi : *this)
|
||||
{
|
||||
const wordList names(allFileObjects.names(Type::typeName, fi.name()));
|
||||
if (names.size())
|
||||
{
|
||||
for (const word& name : names)
|
||||
{
|
||||
set.append(fieldInfo(wordRe(name)));
|
||||
}
|
||||
|
||||
fi.found() = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
|
||||
(
|
||||
DynamicList<fieldInfo>& 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);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -249,10 +249,13 @@ bool Foam::areaWrite::write()
|
||||
|
||||
selected.clear();
|
||||
|
||||
const IOobjectList objects(areaMesh.thisDb(), obr_.time().timeName());
|
||||
IOobjectList objects(0);
|
||||
|
||||
if (loadFromFiles_)
|
||||
{
|
||||
// Check files for a particular time
|
||||
objects = IOobjectList(areaMesh.thisDb(), obr_.time().timeName());
|
||||
|
||||
allFields = objects.names();
|
||||
selected = objects.classes(fieldSelection_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user