Skip to content

I could not open a boundary file in polyMesh directory #824

Description

@yiping-song

Below are the codes which I used to test if I can modify boundary file in the polyMesh directory:

########
from foamlib import FoamFile

below shows that I can open a boundary condition file with no problem

file = FoamFile("rearWing/0/U") # Load a controlDict file
print(file["boundaryField"]["body"]["type"]) # Print the end time
#print(file[None])
file = FoamFile("rearWing/constant/polyMesh/boundary")
print(file["outlet"]["type"])
#########

On running this code, I had following error message:


KeyError Traceback (most recent call last)
Cell In[8], line 8
6 #print(file[None])
7 file = FoamFile("rearWing/constant/polyMesh/boundary")
----> 8 print(file["outlet"]["type"])

File ~/envFoam/lib/python3.12/site-packages/foamlib/_files/files.py:918, in FoamFile.getitem(self, keywords)
913 @OverRide
914 def getitem( # ty: ignore[invalid-method-override]
915 self,
916 keywords: str | tuple[str, ...] | None,
917 ) -> "Data | StandaloneData | FoamFile.SubDict | None":
--> 918 return self.getone(keywords)

File ~/envFoam/lib/python3.12/site-packages/multicollections/abc.py:135, in with_default..wrapper(self, key, default)
127 @functools.wraps(meth)
128 def wrapper(
129 self: _Self,
(...) 132 default: _D | _NO_DEFAULT = _NO_DEFAULT, # ty: ignore[invalid-type-form]
133 ) -> _V | _D:
134 try:
--> 135 return meth(self, key)
136 except KeyError:
137 if default is _NO_DEFAULT:

File ~/envFoam/lib/python3.12/site-packages/foamlib/_files/files.py:870, in FoamFile.getone(self, keywords)
867 keywords = FoamFile._normalized_keywords(keywords) # ty: ignore[no-matching-overload]
869 parsed = self._get_parsed()
--> 870 ret = parsed[keywords]
871 if ret is ...:
872 assert keywords

File ~/envFoam/lib/python3.12/site-packages/foamlib/_files/_parsing/init.py:72, in ParsedFile.getitem(self, keywords)
67 @OverRide
68 def getitem( # ty: ignore[invalid-method-override]
69 self, keywords: tuple[str, ...]
70 ) -> Data | StandaloneData | EllipsisType | None:
---> 72 entry = self._parsed[keywords]
73 return entry.data

File ~/envFoam/lib/python3.12/site-packages/multicollections/init.py:70, in MultiDict.getitem(self, key)
65 """Get the first value for a key.
66
67 Raises a KeyError if the key is not found.
68 """
69 if (indices := self._key_indices.get(key)) is None:
---> 70 raise KeyError(key)
71 return self._items[indices[0]][1]

KeyError: ('outlet',)

Below is the boundary file:

/--------------------------------- C++ -----------------------------------
========= |
\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\ / O peration | Website: https://openfoam.org
\ / A nd | Version: 13
\/ M anipulation |
*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class polyBoundaryMesh;
location "constant/polyMesh";
object boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

8
(
outlet
{
type patch;
nFaces 32;
startFace 6135;
}
lowerWall
{
type patch;
nFaces 50;
startFace 6167;
}
front
{
type empty;
inGroups List 1(empty);
nFaces 4131;
startFace 6217;
}
inlet
{
type patch;
nFaces 32;
startFace 10348;
}
upperWall
{
type patch;
nFaces 50;
startFace 10380;
}
back
{
type empty;
inGroups List 1(empty);
nFaces 4131;
startFace 10430;
}
body
{
type patch;
nFaces 36;
startFace 14561;
}
rearWing
{
type patch;
nFaces 59;
startFace 14597;
}
)

// ************************************************************************* //

I can see what is the cause of the problem but I do not know how to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions