mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support find via keyType for coordinateSystems
- findAll() method returns a labelList of all matching names
- find() method returns the index to the first matching name
For example, use a regex to specify alternative coordinate systems
in porousZones
(
"cat1?(Back|Front)*"
{
coordinateSystem "(cat1|system_10)";
porosity 0.781;
...
}
)
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -136,37 +136,36 @@ Foam::coordinateSystem::coordinateSystem
|
||||
{
|
||||
const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);
|
||||
|
||||
// a simple entry is a lookup into global coordinateSystems
|
||||
// non-dictionary entry is a lookup into global coordinateSystems
|
||||
if (entryPtr && !entryPtr->isDict())
|
||||
{
|
||||
word csName;
|
||||
entryPtr->stream() >> csName;
|
||||
keyType key(entryPtr->stream());
|
||||
|
||||
const coordinateSystems& csLst = coordinateSystems::New(obr);
|
||||
const coordinateSystems& lst = coordinateSystems::New(obr);
|
||||
const label id = lst.find(key);
|
||||
|
||||
label csId = csLst.find(csName);
|
||||
if (debug)
|
||||
{
|
||||
Info<< "coordinateSystem::coordinateSystem"
|
||||
"(const dictionary&, const objectRegistry&):"
|
||||
<< nl << "using global coordinate system: "
|
||||
<< csName << "=" << csId << endl;
|
||||
<< key << "=" << id << endl;
|
||||
}
|
||||
|
||||
if (csId < 0)
|
||||
if (id < 0)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"coordinateSystem::coordinateSystem"
|
||||
"(const dictionary&, const objectRegistry&)"
|
||||
) << "could not find coordinate system: " << csName << nl
|
||||
<< "available coordinate systems: " << csLst.toc() << nl << nl
|
||||
) << "could not find coordinate system: " << key << nl
|
||||
<< "available coordinate systems: " << lst.toc() << nl << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// copy coordinateSystem, but assign the name as the typeName
|
||||
// to avoid strange things in writeDict()
|
||||
operator=(csLst[csId]);
|
||||
operator=(lst[id]);
|
||||
name_ = typeName_();
|
||||
}
|
||||
else
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -26,6 +26,7 @@ License
|
||||
#include "coordinateSystems.H"
|
||||
#include "IOPtrList.H"
|
||||
#include "Time.H"
|
||||
#include "stringListOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -97,13 +98,25 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::coordinateSystems::find(const word& keyword) const
|
||||
Foam::label Foam::coordinateSystems::find(const keyType& key) const
|
||||
{
|
||||
forAll(*this, i)
|
||||
if (key.isPattern())
|
||||
{
|
||||
if (keyword == operator[](i).name())
|
||||
labelList allFound = findAll(key);
|
||||
// return first element
|
||||
if (!allFound.empty())
|
||||
{
|
||||
return i;
|
||||
return allFound[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
forAll(*this, i)
|
||||
{
|
||||
if (key == operator[](i).name())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,9 +124,34 @@ Foam::label Foam::coordinateSystems::find(const word& keyword) const
|
||||
}
|
||||
|
||||
|
||||
bool Foam::coordinateSystems::found(const word& keyword) const
|
||||
Foam::labelList Foam::coordinateSystems::findAll(const keyType& key) const
|
||||
{
|
||||
return find(keyword) >= 0;
|
||||
labelList allFound;
|
||||
if (key.isPattern())
|
||||
{
|
||||
allFound = findStrings(key, toc());
|
||||
}
|
||||
else
|
||||
{
|
||||
allFound.setSize(size());
|
||||
label nFound = 0;
|
||||
forAll(*this, i)
|
||||
{
|
||||
if (key == operator[](i).name())
|
||||
{
|
||||
allFound[nFound++] = i;
|
||||
}
|
||||
}
|
||||
allFound.setSize(nFound);
|
||||
}
|
||||
|
||||
return allFound;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::coordinateSystems::found(const keyType& key) const
|
||||
{
|
||||
return find(key) >= 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -97,11 +97,14 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Find and return index for a given keyword, returns -1 if not found
|
||||
label find(const word& key) const;
|
||||
//- Find and return index for the first match, returns -1 if not found
|
||||
label find(const keyType& key) const;
|
||||
|
||||
//- Search for given keyword
|
||||
bool found(const word& keyword) const;
|
||||
//- Find and return indices for all matches
|
||||
labelList findAll(const keyType& key) const;
|
||||
|
||||
//- Search for given key
|
||||
bool found(const keyType& key) const;
|
||||
|
||||
//- Return the table of contents (list of all keywords)
|
||||
wordList toc() const;
|
||||
|
||||
Reference in New Issue
Block a user