mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: allow modifiable access to IOobject local(), as per instance()
ENH: simplify code by using fieldTypes::is_xxx() tests
This commit is contained in:
@ -42,7 +42,7 @@ using namespace Foam;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
stringList strings
|
||||
{
|
||||
({
|
||||
"hello",
|
||||
"heello",
|
||||
"heeello",
|
||||
@ -52,7 +52,7 @@ int main(int argc, char *argv[])
|
||||
"okey",
|
||||
"okkey",
|
||||
"okkkey",
|
||||
};
|
||||
});
|
||||
labelList matches;
|
||||
|
||||
wordRes matcher1(ICharStream("( okey \"[hy]e+.*\" )")());
|
||||
@ -72,12 +72,14 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
Info<< "Match found using ListOps = "
|
||||
<< ListOps::found(strings, regExp(".*ee.*")) << nl;
|
||||
|
||||
Info<< "First index = "
|
||||
<< ListOps::find(strings, regExp(".*ee.*")) << nl;
|
||||
{
|
||||
regExp matcher(".*ee.*");
|
||||
|
||||
Info<< "Match found using ListOps = "
|
||||
<< ListOps::found_if(strings, matcher) << nl
|
||||
<< "First index = "
|
||||
<< ListOps::find_if(strings, matcher) << nl;
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
matches = findMatchingStrings(matcher1, strings);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -857,16 +857,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
if
|
||||
(
|
||||
obj.isHeaderClass<volScalarField>()
|
||||
|| obj.isHeaderClass<volVectorField>()
|
||||
|| obj.isHeaderClass<volSphericalTensorField>()
|
||||
|| obj.isHeaderClass<volTensorField>()
|
||||
|| obj.isHeaderClass<volSymmTensorField>()
|
||||
|| obj.isHeaderClass<surfaceScalarField>()
|
||||
|| obj.isHeaderClass<surfaceVectorField>()
|
||||
|| obj.isHeaderClass<surfaceSphericalTensorField>()
|
||||
|| obj.isHeaderClass<surfaceSymmTensorField>()
|
||||
|| obj.isHeaderClass<surfaceTensorField>()
|
||||
Foam::fieldTypes::is_volume(obj.headerClassName())
|
||||
|| Foam::fieldTypes::is_surface(obj.headerClassName())
|
||||
)
|
||||
{
|
||||
objects.add(objPtr);
|
||||
|
||||
@ -86,7 +86,7 @@ void constructVolFields(fvMesh& mesh, const vtkUnstructuredReader& reader)
|
||||
);
|
||||
auto& fld = tfld.ref();
|
||||
fld.instance() = mesh.time().timeName();
|
||||
fld.writeOpt() = IOobject::AUTO_WRITE;
|
||||
fld.writeOpt(IOobject::AUTO_WRITE);
|
||||
|
||||
// Fill cell values
|
||||
fld.internalFieldRef().field() =
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -383,29 +383,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
if
|
||||
(
|
||||
io.isHeaderClass<volScalarField>()
|
||||
|| io.isHeaderClass<volVectorField>()
|
||||
|| io.isHeaderClass<volSphericalTensorField>()
|
||||
|| io.isHeaderClass<volSymmTensorField>()
|
||||
|| io.isHeaderClass<volTensorField>()
|
||||
|
||||
|| io.isHeaderClass<surfaceScalarField>()
|
||||
|| io.isHeaderClass<surfaceVectorField>()
|
||||
|| io.isHeaderClass<surfaceSphericalTensorField>()
|
||||
|| io.isHeaderClass<surfaceSymmTensorField>()
|
||||
|| io.isHeaderClass<surfaceTensorField>()
|
||||
|
||||
|| io.isHeaderClass<pointScalarField>()
|
||||
|| io.isHeaderClass<pointVectorField>()
|
||||
|| io.isHeaderClass<pointSphericalTensorField>()
|
||||
|| io.isHeaderClass<pointSymmTensorField>()
|
||||
|| io.isHeaderClass<pointTensorField>()
|
||||
|
||||
|| io.isHeaderClass<volScalarField::Internal>()
|
||||
|| io.isHeaderClass<volVectorField::Internal>()
|
||||
|| io.isHeaderClass<volSphericalTensorField::Internal>()
|
||||
|| io.isHeaderClass<volSymmTensorField::Internal>()
|
||||
|| io.isHeaderClass<volTensorField::Internal>()
|
||||
Foam::fieldTypes::is_volume(io.headerClassName())
|
||||
|| Foam::fieldTypes::is_internal(io.headerClassName())
|
||||
|| Foam::fieldTypes::is_surface(io.headerClassName())
|
||||
|| Foam::fieldTypes::is_point(io.headerClassName())
|
||||
)
|
||||
{
|
||||
Info<< " Reading " << io.headerClassName()
|
||||
|
||||
@ -57,14 +57,7 @@ forAll(meshes, regioni)
|
||||
if (!doPointValues)
|
||||
{
|
||||
// Prune point fields if disabled
|
||||
objects.filterClasses
|
||||
(
|
||||
[](const word& clsName)
|
||||
{
|
||||
return fieldTypes::point.found(clsName);
|
||||
},
|
||||
true // prune
|
||||
);
|
||||
objects.filterClasses(Foam::fieldTypes::is_point, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||
@ -28,8 +28,7 @@ if (doFiniteArea)
|
||||
|
||||
autoPtr<faMesh> faMeshPtr;
|
||||
|
||||
const label nAreaFields =
|
||||
faObjects.count(stringListOps::foundOp<word>(fieldTypes::area));
|
||||
const label nAreaFields = faObjects.count(Foam::fieldTypes::is_area);
|
||||
|
||||
if (nAreaFields || withMeshIds)
|
||||
{
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||
@ -53,10 +53,7 @@ if (doLagrangian)
|
||||
}
|
||||
|
||||
// Limited to basic IOField types
|
||||
cloudObjs.filterClasses
|
||||
(
|
||||
stringListOps::foundOp<word>(fieldTypes::basic)
|
||||
);
|
||||
cloudObjs.filterClasses(Foam::fieldTypes::is_basic);
|
||||
|
||||
// Are there cloud fields (globally)?
|
||||
if (returnReduceAnd(cloudObjs.empty()))
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||
@ -23,10 +23,7 @@ Description
|
||||
{
|
||||
using reportFields = foamToVtkReportFields;
|
||||
|
||||
const label nVolFields =
|
||||
(
|
||||
objects.count(stringListOps::foundOp<word>(fieldTypes::volume))
|
||||
);
|
||||
const label nVolFields = objects.count(Foam::fieldTypes::is_volume);
|
||||
|
||||
reportFields::volume(Info, objects);
|
||||
|
||||
|
||||
@ -24,21 +24,21 @@ Description
|
||||
const label nVolFields =
|
||||
(
|
||||
(doInternal || doBoundary)
|
||||
? objects.count(stringListOps::foundOp<word>(fieldTypes::volume))
|
||||
? objects.count(Foam::fieldTypes::is_volume)
|
||||
: 0
|
||||
);
|
||||
|
||||
const label nDimFields =
|
||||
(
|
||||
(doInternal || doBoundary)
|
||||
? objects.count(stringListOps::foundOp<word>(fieldTypes::internal))
|
||||
? objects.count(Foam::fieldTypes::is_internal)
|
||||
: 0
|
||||
);
|
||||
|
||||
label nPointFields =
|
||||
(
|
||||
doPointValues
|
||||
? objects.count(stringListOps::foundOp<word>(fieldTypes::point))
|
||||
? objects.count(Foam::fieldTypes::is_point)
|
||||
: 0
|
||||
);
|
||||
|
||||
|
||||
@ -803,14 +803,7 @@ int main(int argc, char *argv[])
|
||||
if (!doPointValues)
|
||||
{
|
||||
// Prune point fields if disabled
|
||||
objects.filterClasses
|
||||
(
|
||||
[](const word& clsName)
|
||||
{
|
||||
return fieldTypes::point.found(clsName);
|
||||
},
|
||||
true // prune
|
||||
);
|
||||
objects.filterClasses(Foam::fieldTypes::is_point, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -104,16 +104,7 @@ IOobjectList preFilterFields
|
||||
|
||||
const IOobject& io = *(iter.val());
|
||||
|
||||
if
|
||||
(
|
||||
//OR: fieldTypes::basic.found(io.headerClassName())
|
||||
io.isHeaderClass<IOField<label>>()
|
||||
|| io.isHeaderClass<IOField<scalar>>()
|
||||
|| io.isHeaderClass<IOField<vector>>()
|
||||
|| io.isHeaderClass<IOField<sphericalTensor>>()
|
||||
|| io.isHeaderClass<IOField<symmTensor>>()
|
||||
|| io.isHeaderClass<IOField<tensor>>()
|
||||
)
|
||||
if (Foam::fieldTypes::is_basic(io.headerClassName()))
|
||||
{
|
||||
// Transfer from cloudObjects -> filteredObjects
|
||||
filteredObjects.add(cloudObjects.remove(fldName));
|
||||
|
||||
@ -647,10 +647,10 @@ void Foam::PDRarrays::addBlockage
|
||||
|
||||
const word patchName = word::validate(identifier.substr(0, spc));
|
||||
|
||||
patchNum = ListOps::find
|
||||
patchNum = ListOps::find_if
|
||||
(
|
||||
patches,
|
||||
[=](const PDRpatchDef& p){ return patchName == p.patchName; },
|
||||
[&](const PDRpatchDef& p){ return patchName == p.patchName; },
|
||||
1 // skip 0 (blocked face)
|
||||
);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -505,7 +505,7 @@ public:
|
||||
//- Return name of the class name read from header
|
||||
inline const word& headerClassName() const noexcept;
|
||||
|
||||
//- Return non-constant access to the class name read from header
|
||||
//- Modifiable access to the class name read from header
|
||||
inline word& headerClassName() noexcept;
|
||||
|
||||
//- Return the optional note
|
||||
@ -572,12 +572,15 @@ public:
|
||||
//- Read access to instance path component
|
||||
inline const fileName& instance() const noexcept;
|
||||
|
||||
//- Write access to instance path component
|
||||
//- Modifiable access to instance path component
|
||||
inline fileName& instance() noexcept;
|
||||
|
||||
//- Read access to local path component
|
||||
inline const fileName& local() const noexcept;
|
||||
|
||||
//- Modifiable access to the local path component
|
||||
inline fileName& local() noexcept;
|
||||
|
||||
//- The complete path for the object (with instance, local,...).
|
||||
fileName path() const;
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -288,6 +288,12 @@ inline const Foam::fileName& Foam::IOobject::local() const noexcept
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName& Foam::IOobject::local() noexcept
|
||||
{
|
||||
return local_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::fileName Foam::IOobject::objectPath() const
|
||||
{
|
||||
return path()/name();
|
||||
|
||||
@ -77,7 +77,7 @@ bool Foam::fieldTypes::is_basic(const word& clsName)
|
||||
return
|
||||
(
|
||||
clsName.ends_with("Field")
|
||||
&& fieldTypes::basic.contains(clsName)
|
||||
&& Foam::fieldTypes::basic.contains(clsName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -102,8 +102,8 @@ bool Foam::fieldTypes::is_point(const word& clsName)
|
||||
{
|
||||
return
|
||||
(
|
||||
clsName.starts_with("point") // && clsName.ends_with("Field")
|
||||
&& fieldTypes::point.contains(clsName)
|
||||
clsName.starts_with("point") && clsName.ends_with("Field")
|
||||
&& Foam::fieldTypes::point.contains(clsName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -335,25 +335,20 @@ namespace Foam
|
||||
namespace stringListOps
|
||||
{
|
||||
|
||||
//- Functor to determine if a string is exists in a list of strings.
|
||||
// For example,
|
||||
//
|
||||
// \code
|
||||
// reduce(text, stringListOps::foundOp<word>(myNames));
|
||||
// \endcode
|
||||
//- Functor to determine if a string exists in a list of strings.
|
||||
template<class StringType>
|
||||
struct foundOp
|
||||
{
|
||||
const UList<StringType>& values;
|
||||
|
||||
foundOp(const UList<StringType>& list)
|
||||
foundOp(const UList<StringType>& list) noexcept
|
||||
:
|
||||
values(list)
|
||||
{}
|
||||
|
||||
bool operator()(const std::string& text) const
|
||||
{
|
||||
return values.found(text);
|
||||
return values.contains(text);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -162,8 +162,18 @@ bool Foam::fieldTypes::is_area(const word& clsName)
|
||||
{
|
||||
return
|
||||
(
|
||||
clsName.starts_with("area") // && clsName.ends_with("Field")
|
||||
&& fieldTypes::area.contains(clsName)
|
||||
clsName.starts_with("area") && clsName.ends_with("Field")
|
||||
&& Foam::fieldTypes::area.contains(clsName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fieldTypes::is_area_internal(const word& clsName)
|
||||
{
|
||||
return
|
||||
(
|
||||
clsName.starts_with("area") && clsName.ends_with("::Internal")
|
||||
&& Foam::fieldTypes::area_internal.contains(clsName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -96,12 +96,15 @@ namespace fieldTypes
|
||||
//- Standard area field types (scalar, vector, tensor, etc)
|
||||
extern const wordList area;
|
||||
|
||||
//- Standard dimensioned field types (scalar, vector, tensor, etc)
|
||||
//- Standard area internal field types (scalar, vector, tensor, etc)
|
||||
extern const wordList area_internal;
|
||||
|
||||
//- Test if the class name appears to be an area field
|
||||
bool is_area(const word& clsName);
|
||||
|
||||
//- Test if the class name appears to be an area internal field
|
||||
bool is_area_internal(const word& clsName);
|
||||
|
||||
} // End namespace fieldTypes
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -100,8 +100,8 @@ bool Foam::fieldTypes::is_surface(const word& clsName)
|
||||
{
|
||||
return
|
||||
(
|
||||
clsName.starts_with("surface") // && clsName.ends_with("Field")
|
||||
&& fieldTypes::surface.contains(clsName)
|
||||
clsName.starts_with("surface") && clsName.ends_with("Field")
|
||||
&& Foam::fieldTypes::surface.contains(clsName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ namespace fieldTypes
|
||||
//- Standard surface field types (scalar, vector, tensor, etc)
|
||||
extern const wordList surface;
|
||||
|
||||
//- Test if the class name appears to be an surface field
|
||||
//- Test if the class name appears to be a surface field
|
||||
bool is_surface(const word& clsName);
|
||||
|
||||
} // End namespace fieldTypes
|
||||
|
||||
@ -159,12 +159,22 @@ const Foam::wordList Foam::fieldTypes::volume
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fieldTypes::is_internal(const word& clsName)
|
||||
{
|
||||
return
|
||||
(
|
||||
clsName.starts_with("vol") && clsName.ends_with("::Internal")
|
||||
&& Foam::fieldTypes::internal.contains(clsName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fieldTypes::is_volume(const word& clsName)
|
||||
{
|
||||
return
|
||||
(
|
||||
clsName.starts_with("vol") // && clsName.ends_with("Field")
|
||||
&& fieldTypes::volume.contains(clsName)
|
||||
clsName.starts_with("vol") && clsName.ends_with("Field")
|
||||
&& Foam::fieldTypes::volume.contains(clsName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -93,12 +93,15 @@ typedef
|
||||
namespace fieldTypes
|
||||
{
|
||||
|
||||
//- Standard dimensioned field types (scalar, vector, tensor, etc)
|
||||
//- Standard volume internal field types (scalar, vector, tensor, etc)
|
||||
extern const wordList internal;
|
||||
|
||||
//- Standard volume field types (scalar, vector, tensor, etc)
|
||||
extern const wordList volume;
|
||||
|
||||
//- Test if the class name appears to be a volume internal field
|
||||
bool is_internal(const word& clsName);
|
||||
|
||||
//- Test if the class name appears to be a volume field
|
||||
bool is_volume(const word& clsName);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -315,8 +315,8 @@ bool Foam::areaWrite::write()
|
||||
|
||||
if
|
||||
(
|
||||
fieldTypes::area.contains(clsName)
|
||||
|| fieldTypes::area_internal.contains(clsName)
|
||||
Foam::fieldTypes::is_area(clsName)
|
||||
|| Foam::fieldTypes::is_area_internal(clsName)
|
||||
)
|
||||
{
|
||||
nAreaFields += n;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -29,7 +29,7 @@ License
|
||||
#include "dictionary.H"
|
||||
#include "Time.H"
|
||||
#include "areaFields.H"
|
||||
#include "stringListOps.H" // For stringListOps::foundOp()
|
||||
#include "volFields.H"
|
||||
#include "foamVtkInternalWriter.H"
|
||||
#include "foamVtkPatchWriter.H"
|
||||
#include "foamVtkSeriesWriter.H"
|
||||
@ -332,11 +332,7 @@ bool Foam::functionObjects::vtkWrite::write()
|
||||
const label nVolFields =
|
||||
(
|
||||
(doInternal_ || doBoundary_)
|
||||
? baseMesh.count
|
||||
(
|
||||
stringListOps::foundOp<word>(fieldTypes::volume),
|
||||
candidateNames
|
||||
)
|
||||
? baseMesh.count(Foam::fieldTypes::is_volume, candidateNames)
|
||||
: 0
|
||||
);
|
||||
|
||||
@ -345,11 +341,7 @@ bool Foam::functionObjects::vtkWrite::write()
|
||||
const label nDimFields = 0;
|
||||
// (
|
||||
// (doInternal_ || doBoundary_)
|
||||
// ? baseMesh.count
|
||||
// (
|
||||
// stringListOps::foundOp<word>(fieldTypes::internal),
|
||||
// candidateNames
|
||||
// )
|
||||
// ? baseMesh.count(Foam::fieldTypes::is_internal, candidateNames)
|
||||
// : 0
|
||||
// );
|
||||
|
||||
|
||||
@ -127,11 +127,11 @@ Foam::IOobjectList Foam::sampledSurfaces::preCheckFields()
|
||||
const word& clsName = iter.key();
|
||||
const label n = iter.val().size();
|
||||
|
||||
if (fieldTypes::volume.contains(clsName))
|
||||
if (Foam::fieldTypes::is_volume(clsName))
|
||||
{
|
||||
nVolumeFields += n;
|
||||
}
|
||||
else if (fieldTypes::surface.contains(clsName))
|
||||
else if (Foam::fieldTypes::is_surface(clsName))
|
||||
{
|
||||
nSurfaceFields += n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user